15,792,266 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Python questions
View PHP questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Romain TAILLANDIER (Top 14 by date)
Romain TAILLANDIER
16-Dec-11 3:30am
View
I am a quite new programmer (near 10 years of C#) comparing to you Jack 'Dinosaur' Dingler :)
I agree, switch is not necessary. as the else is. (if(a){...}if(!a){...}
There this many form of loop, for, while, doWhile, (and now foreach in C#), only one should be necessary
There is the linq language ..., not necessary
There is a swarm of unnecessary keywords, function concepts ...
But it is just a easy way to do, read and maintain the things.
Being a dinosaur, wouldn't you exclusivly use assembler ? or perfored card ? :)
I am aout of the question, it's happend ... but may i suggest you to take a look to
brainfuck
? I am sure you would like it ! Nothing unnecessary !
Finally back to your question, I try to reply in C# with your permition (not good enough in C++).
I would have created a hashtable containning numbers (100, 201, 300, 305...) as keys, and type names ("Namespace.Circle", "System.String" ...) as string values.
Then getting the number i would retrieve the type name using this table and use the reflection.emit to instanciate the type. (not so far from Emilio Garavaglia solution)
Romain TAILLANDIER
16-Dec-11 2:38am
View
You have to start with some MSDN documentation ...
http://msdn.microsoft.com/fr-fr/library/system.io.ports.serialport.aspx
Romain TAILLANDIER
13-Dec-11 7:28am
View
Start by trying to set the baud rate to 115200*8. you will gain a little during the transmition. according to your 5ms, even one 0.5 ms is a good gain ...
You can try to set your reading and writing threads to higher priority.
the 15ms may contains the delay used by windows to give some processor time to your process.
I can't understand why you need timers of 5ms ?
The better way to get the better time reaction is to reply in the same function as you receive like
public void SerialPort_Receved(..)
{
SerialPort.read(buffer,0,SerialPort.ByteToRead);
byte[] reply = this.BuildMyReply(buffer);
SerialPort.Write(reply,0,reply.Lenght);
}
if you use an additional timer, it should be less fast.
Romain TAILLANDIER
Romain TAILLANDIER
13-Dec-11 3:18am
View
It is not clear if your 5ms constraint is
- between start of frame and end of frame, OR
- between end of reception and start of emission ....
If i do not mistake, your have 2 delay :
- Time for react to a reception
- Time a write transmition
Time to write 64 bytes @115200 Baud (115200 bit/seconds)
should be 512/115200 = 0.0044 sec = 4.4ms, so you have less than one ms to create the reply ...
If your RF dongle is USB, you probably have a usb-serial converter inside. So your speed should be only limited by usb speed AND driver of the USB-COM converter. That way you (usually) should be able to set up the BaudRate to 115200*8 (and more for USB2), but i believe Framework is limited to 115200*8.
Now to speed up you time of react, it really depend on your implementation.
How do you measure the time of your reaction ?
I have notice that in debug, Console.WriteLine and Debug.WriteLine are really slow down all times i can measure.
Romain TAILLANDIER
Romain TAILLANDIER
12-Dec-11 7:54am
View
Thread.sleep is not recommanded on UI thread that's right. But if it sleep a very few time (less than 200-300), user can't observe the delay. You can add Application.DoEvents() in the sleep loop, to let the user have the control, and the UI refreshing good. You also can freeze the UI while the program communicate with the peripheral, simply by activate a wait cursor (this.Cursor = Cursors.Wait;)
According to my experience, i drove tens of rfid peripherals using C#, massively constructed on waiting for ByteToRead > 0, and i never experienced problems using this, since the SerialPort class exists on compact framework 2. (didn't exists in CF1).
Most of the peripheral i drive are self maid one based on microchip PIC microcontrollers. Do you now ASPYCOM[^]?
It allow you to spy a com port and see if your program and your peripheral communicate as waited
Romain TAILLANDIER
12-Dec-11 4:46am
View
SORRY, I haven't seen it was so long ...
I think i should works anyway, please update the 2 directory where to copy and past the files ...
string PDASynchDir = "\\MyDirectoryToCopy";
string PcSynchDir = "C:\\DirectoryWhereToSave";
Hope it will be usefull
Romain TAILLANDIER
12-Dec-11 4:44am
View
}
#endregion
#region in case of windows shuting down
private const int WM_QUERYENDSESSION = 0x11;
///
/// WndProc, in case of shut down windows, this program may prevent the shutdown. so take care of that.
///
/// <param name="m"></param>
protected override void WndProc(ref System.Windows.Forms.Message m)
{
// POURQUOI ?
// lorsque le PC veut fermer la session, ou entrer en veille, il en est empecher apr ce programme,
// a cause de rapi sans doute.
// On veut donc fermer ce programme manuellement (si on peut dire) au changement de session
// on écoute donc cette évenement dans les messages windows.
// et on ferme rapi lorsqu'il se produit.
// Mise dans systemShutdown la présence du message fermeture Windows
if(m.Msg == WM_QUERYENDSESSION)
{
if(this.MyRapi != null)
this.MyRapi.Disconnect();
base.Dispose();
}
base.WndProc(ref m);
}
#endregion
}
}
Romain TAILLANDIER
12-Dec-11 4:43am
View
if(ErrorCount <= 0)
{
ShowStatus("Download is success");
}
else
{
ShowStatus("Download get " + ErrorCount + " error(s)");
}
return ErrorCount;
}
#endregion
#region affichage
///
/// Sert a faire bouger la barre d'avancement
///
/// <param name="pourcent"></param>
private void Avancement(int pourcent)
{
if(this.InvokeRequired)
{
this.Invoke(new GenericHandler<int>(this.Avancement), new object[] { pourcent });
return;
}
this.MyProgressBar.Value = pourcent;
}
///
/// Affichage de messages
///
/// <param name="status"></param>
private void ShowStatus(string status)
{
if(this.InvokeRequired)
{
this.Invoke(new GenericHandler<string>(this.ShowStatus), new object[] { status });
return;
}
this.lblStatus.Text = status;
this.lblStatus.Refresh();
Application.DoEvents();
}
///
/// Affichage de messages
///
/// <param name="activ"></param>
private void ShowActivity(string activ)
{
if(this.InvokeRequired)
{
this.Invoke(new GenericHandler<string>(this.ShowActivity), new object[] { activ });
return;
}
this.lblActivity.Text = activ;
this.lblActivity.Refresh();
Application.DoEvents();
}
///
/// Permet ou non l'utilisation des boutons de synchronisation
///
/// <param name="enabled"></param>
private void EnableSyncBouttons(bool enabled)
{
if(this.InvokeRequired)
{
this.Invoke(new GenericHandler<bool>(this.EnableSyncBouttons), new object[] { enabled });
return;
}
this.btnSyncUP.Enabled = enabled;
//this.btnExplorer.Enabled = enabled;
}
#endregion
#region interactions utilisateurs, apropos, agrandir, réduire, iconification
private void btnReduire_Click(object sender, EventArgs e)
{
this.Minimize();
}
private void ctxAgrandir_Click(object sender, EventArgs e)
{
this.Restore();
}
private void Quitter_Click(object sender, EventArgs e)
{
this.MyNotifyIcon.Visible = false;
this.MyNotifyIcon.Dispose();
base.Dispose();
System.Windows.Forms.Application.Exit();
}
private void ctxReduire_Click(object sender, EventArgs e)
{
this.Minimize();
}
private void MyNotifyIcon_DoubleClick(object sender, EventArgs e)
{
if(base.Visible)
{
this.Minimize();
}
else
{
this.Restore();
}
}
private void MOBIshotSysTray_Load(object sender, EventArgs e)
{
this.Minimize();
base.Hide();
}
protected void Restore()
{
if(this.InvokeRequired)
{
this.Invoke(new VoidHandler(this.Restore), null);
return;
}
if(base.Visible)
this.Activate();
else
base.Visible = true;
}
protected void Minimize()
{
if(this.InvokeRequired)
{
this.Invoke(new VoidHandler(this.Minimize), null);
return;
}
this.Visible = false;
Romain TAILLANDIER
12-Dec-11 4:42am
View
try
{
// download files
this.DO_CopyFromDevice(list1);
MessageBox.Show("Exportation OK");
}
catch(Exception e)
{
// On arrete tout, on log les erreurs
ShowActivity("Aucune");
ShowStatus("Erreur dans la remontée des données depuis le PDA");
this.MyProgressBar.Value = 0;
this.SyncIsRunning = false;
MessageBox.Show("Erreur lors du téléchargement des fichier depuis le PDA");
Console.WriteLine(e);
return;
}
this.ShowStatus("Remontée des données terminée avec succès");
}
// on a finit le downoad et l'upload.
this.ShowActivity(string.Empty);
this.MyProgressBar.Value = 0;
}
catch(Exception exception1)
{
// manage errors...
Console.WriteLine(exception1.Message);
ShowStatus("Erreur inconnue");
ShowActivity("Interruption prématurée");
this.MyProgressBar.Value = 0;
}
// on sait pas dans quel etat mais on a fini.
//this.Minimize();
this.SyncIsRunning = false;
}
/// On fait le téléchargement.
///
/// <param name="list1">la liste des ficheirs a télécharger</param>
/// <returns>Le nombre d'erreurs
private int DO_CopyFromDevice(FileList list1)
{
int ErrorCount = 0;
ShowActivity("download " + list1.Count.ToString() + " file(s)");
foreach(FileInformation fi in list1)
{
//string PCFileName = Path.Combine(Config.PcToServerDir, fi.FileName);
string PCFileName = Path.Combine(PcSynchDir, Path.GetFileNameWithoutExtension(fi.FileName) + "_" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + Path.GetExtension(fi.FileName));
string PDAFileName = Path.Combine(PDASynchDir, fi.FileName);
if(!Directory.Exists(PcSynchDir))
{
Directory.CreateDirectory(PcSynchDir);
}
if(File.Exists(PCFileName))
{
File.Delete(PCFileName);
}
ShowActivity("Téléchargement du fichier " + fi.FileName);
ShowStatus("En cours...");
bool DL_OK = false;
try
{
DL_OK = false;
this.MyRapi.CopyFileFromDevice(PCFileName, PDAFileName, true);
DL_OK = true;
ShowStatus("OK");
// if get there, file is succesfully copied
// remove it form the device ?
if(DL_OK)
{
ShowActivity("Suppression du fichier " + fi.FileName);
this.MyRapi.DeleteDeviceFile(PDAFileName);
ShowStatus("OK");
}
}
catch(Exception e)
{
ErrorCount++;
ShowStatus("Erreur");
//this.NePasEffacerCesFichiersDuPDA.Add(PDAFileName);
// si le téléchargement est un echec, on supprime le fichier, pas la peine de se retrouver avec un
// fichier moisi
if(!DL_OK && File.Exists(PCFileName))
File.Delete(PCFileName);
}
this.MyProgressBar.PerformStep();
}
ShowActivity("Aucune");
if(E
Romain TAILLANDIER
12-Dec-11 4:41am
View
// Lancement des event et affihage
this.ShowActivity( "no activity" );
this.ShowStatus( "disconnected" );
this.Minimize();
// Desactive les boutons de synchro
//this.EnableSync, new object[] { false });
this.EnableSyncBouttons(false);
}
///
/// Active sync est en attente
///
private void ActiveSync_Listen()
{
this.ShowStatus("disconnected");
Console.WriteLine("AS Listen");
}
///
/// Active sync is connected
///
private void ActiveSync_Active()
{
Console.WriteLine("AS Active");
this.Restore();
this.ShowActivity("Connection to PDA" );
this.ShowStatus( "Connected" );
// time of starting battery load
this.StartLoadingBattery = DateTime.Now;
// Active sync connected, but not rapi !
System.Threading.Thread.Sleep(1000);
Debug.Write("BTN CONNECT => ");
// Connect the Remote API
this.MyRapi.Connect();
// Active the button
this.EnableSyncBouttons(true);
// IF NEEDED here you can call directly ,
// so the synchro will start just when the device become connected, after active sync ok.
this.btnSyncUP_Click(this, EventArgs.Empty);
}
#endregion
#region SYNCHRO
// Set synch dir
string PDASynchDir = "\\MyDirectoryToCopy"; // directory where files are
string PcSynchDir = "C:\\DirectoryWhereToSave"; // directory on the host PC
private void btnSyncUP_Click(object sender, EventArgs e)
{
this.EnableSyncBouttons(false);
this.Cursor = Cursors.WaitCursor;
this.groupBox1.Visible = true;
if(!this.MyRapi.Connected)
{
MessageBox.Show("Error rapi not conencted");
this.EnableSyncBouttons(false);
this.groupBox1.Visible = false;
this.Cursor = Cursors.Default;
return;
}
this.ShowActivity("SyncUp ...");
this.DO_SynchroUp();
this.Cursor = Cursors.Default;
this.EnableSyncBouttons(true);
this.groupBox1.Visible = false;
}
///
/// this function is supposed to get files from device and copy to host PC.
///
private void DO_SynchroUp()
{
this.SyncIsRunning = true;
try
{
// Si le device n'est aps présent, on arrete tout.
if(!this.MyRapi.DevicePresent)
{
ShowActivity("Aucune");
ShowStatus("Aucun PDA connecté");
this.SyncIsRunning = false;
MessageBox.Show("PDA absent");
return;
}
// Explorer les dossier du PDA
FileList list1 = this.MyRapi.EnumFiles(Path.Combine(PDASynchDir,"*.*"));
// Si présence de fichiers sur le pda,
if(list1 == null)
{
// upload
ShowActivity("nothing");
ShowStatus("error when exploring device");
this.MyProgressBar.Value = 0;
}
else if(list1.Count == 0)
{
// upload
ShowActivity("nothing");
ShowStatus("no file discovered");
this.MyProgressBar.Value = 0;
MessageBox.Show("no file discovered");
}
else
{
Romain TAILLANDIER
12-Dec-11 4:40am
View
this.label1.TabIndex = 5;
this.label1.Text = "Activity";
//
// btnQuit
//
this.btnQuit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnQuit.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnQuit.Location = new System.Drawing.Point(177, 287);
this.btnQuit.Name = "btnQuit";
this.btnQuit.Size = new System.Drawing.Size(75, 23);
this.btnQuit.TabIndex = 2;
this.btnQuit.Text = "Quit";
this.toolTip1.SetToolTip(this.btnQuit, "exit the program");
this.btnQuit.UseVisualStyleBackColor = true;
this.btnQuit.Click += new System.EventHandler(this.Quitter_Click);
//
// SynchronizerSimple
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(357, 322);
this.ControlBox = false;
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.btnQuit);
this.Controls.Add(this.btnMinimize);
this.Controls.Add(this.btnSyncUP);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "SynchronizerSimple";
this.Text = "Synchronisation ";
this.Load += new System.EventHandler(this.SynchronizerSimple_Load);
this.contextMenuStrip1.ResumeLayout(false);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button btnSyncUP;
private System.Windows.Forms.Button btnMinimize;
private System.Windows.Forms.ToolTip toolTip1;
private System.Windows.Forms.ProgressBar MyProgressBar;
private System.Windows.Forms.NotifyIcon MyNotifyIcon;
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
private System.Windows.Forms.ToolStripMenuItem réduireToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem agrandireToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem quitterToolStripMenuItem;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label lblStatus;
private System.Windows.Forms.Label lblActivity;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button btnQuit;
#endregion
#region active sync events
///
/// Active sync est en train de répondre
///
private void ActiveSync_Answer()
{
this.Restore();
this.ShowActivity("Connection au PDA");
this.ShowStatus("running ...");
Console.WriteLine("AS Answer");
}
///
/// Active sync vient de se déco
///
private void ActiveSync_Disconnect()
{
this.MyRapi.Disconnect();
// on a déco le PDA, alors que la synchro était en cours.
if(this.SyncIsRunning)
{
// Log une erreur
Console.WriteLine("unwaited disconnect while synchronizing");
}
else
{
Console.WriteLine("AS disconnected");
}
// Battery Load Time
this.EndLoadingBattery = DateTime.Now;
TimeSpan BatteryLoadTime = EndLoadingBattery - StartLoadingBattery;
Console.WriteLine("Battery load time : " + BatteryLoadTime.TotalHours.ToStrin
Romain TAILLANDIER
12-Dec-11 4:39am
View
//
// contextMenuStrip1
//
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.réduireToolStripMenuItem,
this.agrandireToolStripMenuItem,
this.quitterToolStripMenuItem});
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.Size = new System.Drawing.Size(125, 70);
//
// réduireToolStripMenuItem
//
this.réduireToolStripMenuItem.Name = "réduireToolStripMenuItem";
this.réduireToolStripMenuItem.Size = new System.Drawing.Size(124, 22);
this.réduireToolStripMenuItem.Text = "minimize";
this.réduireToolStripMenuItem.Click += new System.EventHandler(this.btnReduire_Click);
//
// agrandireToolStripMenuItem
//
this.agrandireToolStripMenuItem.Name = "agrandireToolStripMenuItem";
this.agrandireToolStripMenuItem.Size = new System.Drawing.Size(124, 22);
this.agrandireToolStripMenuItem.Text = "maximize";
this.agrandireToolStripMenuItem.Click += new System.EventHandler(this.ctxAgrandir_Click);
//
// quitterToolStripMenuItem
//
this.quitterToolStripMenuItem.Name = "quitterToolStripMenuItem";
this.quitterToolStripMenuItem.Size = new System.Drawing.Size(124, 22);
this.quitterToolStripMenuItem.Text = "quit";
this.quitterToolStripMenuItem.Click += new System.EventHandler(this.Quitter_Click);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.lblStatus);
this.groupBox1.Controls.Add(this.lblActivity);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.MyProgressBar);
this.groupBox1.Location = new System.Drawing.Point(12, 85);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(333, 196);
this.groupBox1.TabIndex = 4;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Synchronization";
this.groupBox1.Visible = false;
//
// label2
//
this.label2.AutoSize = true;
this.label2.ForeColor = System.Drawing.Color.MediumBlue;
this.label2.Location = new System.Drawing.Point(6, 89);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(63, 13);
this.label2.TabIndex = 6;
this.label2.Text = "Actual state";
//
// lblStatus
//
this.lblStatus.AutoEllipsis = true;
this.lblStatus.ForeColor = System.Drawing.Color.MediumBlue;
this.lblStatus.Location = new System.Drawing.Point(24, 104);
this.lblStatus.Name = "lblStatus";
this.lblStatus.Size = new System.Drawing.Size(303, 38);
this.lblStatus.TabIndex = 7;
this.lblStatus.Text = "not connected";
//
// lblActivity
//
this.lblActivity.AutoEllipsis = true;
this.lblActivity.ForeColor = System.Drawing.Color.MediumBlue;
this.lblActivity.Location = new System.Drawing.Point(24, 38);
this.lblActivity.Name = "lblActivity";
this.lblActivity.Size = new System.Drawing.Size(303, 37);
this.lblActivity.TabIndex = 4;
this.lblActivity.Text = "nothing";
//
// label1
//
this.label1.AutoSize = true;
this.label1.ForeColor = System.Drawing.Color.MediumBlue;
this.label1.Location = new System.Drawing.Point(6, 23);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(41, 13);
Romain TAILLANDIER
12-Dec-11 4:38am
View
///
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SynchronizerSimple));
this.btnMinimize = new System.Windows.Forms.Button();
this.MyProgressBar = new System.Windows.Forms.ProgressBar();
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
this.btnSyncUP = new System.Windows.Forms.Button();
this.MyNotifyIcon = new System.Windows.Forms.NotifyIcon(this.components);
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.réduireToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.agrandireToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.quitterToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label2 = new System.Windows.Forms.Label();
this.lblStatus = new System.Windows.Forms.Label();
this.lblActivity = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.btnQuit = new System.Windows.Forms.Button();
this.contextMenuStrip1.SuspendLayout();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// btnMinimize
//
this.btnMinimize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnMinimize.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnMinimize.Location = new System.Drawing.Point(77, 287);
this.btnMinimize.Name = "btnMinimize";
this.btnMinimize.Size = new System.Drawing.Size(75, 23);
this.btnMinimize.TabIndex = 2;
this.btnMinimize.Text = "Minimize";
this.toolTip1.SetToolTip(this.btnMinimize, "Minimize");
this.btnMinimize.UseVisualStyleBackColor = true;
this.btnMinimize.Click += new System.EventHandler(this.btnReduire_Click);
//
// MyProgressBar
//
this.MyProgressBar.Location = new System.Drawing.Point(6, 167);
this.MyProgressBar.Name = "MyProgressBar";
this.MyProgressBar.Size = new System.Drawing.Size(321, 23);
this.MyProgressBar.TabIndex = 3;
this.toolTip1.SetToolTip(this.MyProgressBar, "avancement de la synchronisation");
//
// btnSyncUP
//
this.btnSyncUP.Enabled = false;
this.btnSyncUP.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnSyncUP.ImageAlign = System.Drawing.ContentAlignment.TopCenter;
this.btnSyncUP.Location = new System.Drawing.Point(12, 9);
this.btnSyncUP.Name = "btnSyncUP";
this.btnSyncUP.Size = new System.Drawing.Size(333, 70);
this.btnSyncUP.TabIndex = 0;
this.btnSyncUP.Text = "Export";
this.btnSyncUP.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
this.toolTip1.SetToolTip(this.btnSyncUP, "Get data from device");
this.btnSyncUP.UseVisualStyleBackColor = true;
this.btnSyncUP.Click += new System.EventHandler(this.btnSyncUP_Click);
//
// MyNotifyIcon
//
this.MyNotifyIcon.ContextMenuStrip = this.contextMenuStrip1;
this.MyNotifyIcon.Icon = ((System.Drawing.Icon)(resources.GetObject("MyNotifyIcon.Icon")));
this.MyNotifyIcon.Text = "Synchronizer";
this.MyNotifyIcon.Visible = true;
this.MyNotifyIcon.DoubleClick += new System.EventHandler(this.ctxAgrandir_Click
Romain TAILLANDIER
12-Dec-11 4:37am
View
OK, i have simplified a small synchronizer just for you.
Create a new C# project, add a reference to OpenNetCfDesktop, and this class :
(Don't forget to install Active sync, or Manager for mobile device (not sure of the exact english name)).
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using OpenNETCF.Desktop.Communication;
using System.IO;
using System.Diagnostics;
namespace RomainTAILLANDIER
{
public delegate void GenericHandler<t>(T param);
public delegate void VoidHandler();
public delegate int GenericHandlerWithResult<t>(T param);
public class SynchronizerSimple : Form
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new RomainTAILLANDIER.SynchronizerSimple());
}
#region privates variables
///
/// Connection on Remote API.
///
private RAPI MyRapi;
///
/// if synchro is running
///
private bool SyncIsRunning = false;
///
/// start of battery load
///
public DateTime StartLoadingBattery;
///
/// end of batteryload
///
public DateTime EndLoadingBattery;
#endregion
#region construction
public SynchronizerSimple()
{
try
{
// Init Prop
InitializeComponent();
// Init RAPI
this.MyRapi = new RAPI();
// eveneemnt rapi
this.MyRapi.ActiveSync.Active += new ActiveHandler(this.ActiveSync_Active);
this.MyRapi.ActiveSync.Disconnect += new DisconnectHandler(this.ActiveSync_Disconnect);
this.MyRapi.ActiveSync.Listen += new ListenHandler(this.ActiveSync_Listen);
this.MyRapi.ActiveSync.Answer += new AnswerHandler(this.ActiveSync_Answer);
//this.MyRapi.RAPIConnected += new RAPIConnectedHandler(MyRapi_RAPIConnected);
//this.MyRapi.RAPIDisconnected += new RAPIConnectedHandler(MyRapi_RAPIDisconnected);
}
catch(Exception e)
{
Console.WriteLine(e);
}
}
///
/// on start
///
/// <param name="sender"></param>
/// <param name="e"></param>
private void SynchronizerSimple_Load(object sender, EventArgs e)
{
if(this.MyRapi != null)
{
// Si un PDA est connecté, on fait une connection
if(this.MyRapi.DevicePresent)
{
// on tente une reco
this.MyRapi.Connect();
this.EnableSyncBouttons(this.MyRapi.Connected);
}
else // sinon, on réduit
{
this.Minimize();
}
}
}
///
/// Variable nécessaire au concepteur.
///
private System.ComponentModel.IContainer components = null;
///
/// Nettoyage des ressources utilisées.
///
/// <param name="disposing">true si les ressources managées doivent être supprimées ; sinon, false.</param>
protected override void Dispose(bool disposing)
{
if(disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Code généré par le Concepteur Windows Form
///
/// Méthode requise pour la prise en charge du concepteur - ne modifiez
Show More