Thanks for the reply.
I couldn't use the example you added (can't compile in VB.net or C#).
I wrote a simple program in Vb.Net that does it and also tracks the time drift and enables manual sync .
I will try to post it here .. not sure how to ...
Moris
too bad I cant add an image or the exe for the program so others can use it ...
when I press "add image icon" I only get /img ... I guess I am to dumb to use it ...
Here is the source for the VB.Net for it
Add two buttons and two listboxes and this code and you should get what you need:
Public Class Form1
Public RecString As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Me.AddListBoxItem(DateDiff("s", "1/1/1970 0:00 PM", Now))
'Second(Now) + Minute(Now) * 60 & Hour(Now) * 3600 &
SerialPort1.WriteLine("T" & DateDiff("s", "1/1/1970 0:00 AM", Now))
End Sub
Private Sub Form1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Leave
SerialPort1.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Show all available COM ports.
For Each sp As String In My.Computer.Ports.SerialPortNames
ListBox2.Items.Add(sp)
Next
End Sub
Private Delegate Sub AddListBoxItemInvoker(ByVal item As Object)
Private Sub SerialPort1_DataReceived(ByVal sender As Object, _
ByVal e As IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
RecString = Me.SerialPort1.ReadLine()
Me.AddListBoxItem(RecString)
End Sub
Private Sub AddListBoxItem(ByVal item As Object)
If Me.ListBox1.InvokeRequired Then
'We are on a secondary thread so delegation is required.
Me.ListBox1.Invoke(New AddListBoxItemInvoker(AddressOf AddListBoxItem), _
item)
Else
'We are on the primary thread so add the item.
'System.DateTimeKind.Utc()
Me.ListBox1.Items.Clear()
Me.ListBox1.Items.Add("Arduino:" & vbTab & item)
Me.ListBox1.Items.Add("PC:" & vbTab & Now.ToString)
If IsDate(RecString) Then
Me.ListBox1.Items.Add(DateDiff("s", Now, RecString) & " Secons different")
End If
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Not (ListBox2.SelectedItem = "") Then
SerialPort1.Close()
SerialPort1.PortName = ListBox2.SelectedItem
SerialPort1.Open()
Else
MsgBox("Select a com port to use")
End If
End Sub
End Class