Hi Kurt (and others ),
I just wanted to let you know I managed to get RoboRealm sending the image data through a Pipe to your DIY XBee VB application. So today I controlled my robots using a yellow stanley knife! I’ve not very much experience with VB programming so I did alot of dirty tricks, but it worked though. I’ll work more on this later, if you are interested I can post the dirty files. At the moment I’m running the main Pipe loop inside your CommThread_DoWork sub.
[code]Private Sub CommThread_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles CommThread.DoWork
CommThread.ReportProgress(0)
XBSW.Start()
'Dim Counter As Byte
'=========== From VB Pipe sub Main start =============
Dim dwOpenMode As Integer, dwPipeMode As Integer
Dim res As Integer, bytesRead As Integer, varLen As Integer
Dim varName() As Byte
Dim varData(1024) As Byte
Running = True
'Create the NULL security token for the pipe
pSD = GlobalAlloc(GPTR, SECURITY_DESCRIPTOR_MIN_LENGTH)
res = InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION)
res = SetSecurityDescriptorDacl(pSD, -1, 0, 0)
sa.nLength = Len(sa)
sa.lpSecurityDescriptor = pSD
sa.bInheritHandle = True
Dim op As OVERLAPPED
Dim eventHandle As Long
eventHandle = CreateEvent(0&, False, False, 0&)
op.hEvent = eventHandle
'Create the Named Pipe
dwOpenMode = PIPE_ACCESS_DUPLEX Or FILE_FLAG_WRITE_THROUGH
'dwPipeMode = FILE_FLAG_OVERLAPPED Or PIPE_TYPE_MESSAGE Or PIPE_READMODE_MESSAGE
dwPipeMode = PIPE_TYPE_MESSAGE Or PIPE_READMODE_MESSAGE
hPipe = CreateNamedPipe(szPipeName, dwOpenMode, dwPipeMode, 10, 10000, 2000, 10000, sa)
'Waiting
res = ConnectNamedPipe(hPipe, Nothing)
'res = MsgWaitForMultipleObjects(1, eventHandle, 0&, INFINITE, QS_ALLINPUT)
If res > 0 Then
'Connected
imageCount = 0
Dim bytesWrite = 0
varLen = 0
'===== VB Pipe end ======
Using com1 As IO.Ports.SerialPort = _
My.Computer.Ports.OpenSerialPort(XBeeCommport, 38400, IO.Ports.Parity.None)
com1.Handshake = IO.Ports.Handshake.None
com1.DtrEnable = False
com1.NewLine = Chr(13)
While Not CommThread.CancellationPending ' turn off the thread...
'=========== VB Pipe Loop start==========
Do While Running
imageCount = imageCount + 1
'Processing & imageCount
Do While Running
'DoEvents()
' read in variable length
varLen = ReadInteger(hPipe)
' if length <=0 on the variable name then we're done
If varLen <= 0 Then Exit Do
' read in variable name but if the name is longer than 64 characters
' then grab the first 64 chars only
If varLen < MAX_VARNAME_SIZE Then
bytesRead = varLen
ReDim varName(varLen - 1)
ReadFile(hPipe, varName(0), varLen, bytesRead, Nothing)
Else
bytesRead = 64
' read in first 64 chars
ReDim varName(64 - 1)
ReadFile(hPipe, varName(0), MAX_VARNAME_SIZE - 1, bytesRead, Nothing)
' skip over remaining chars
SetFilePointer(hPipe, varLen - MAX_VARNAME_SIZE + 1, 0, FILE_CURRENT)
End If
' read in the variable's data length
varLen = ReadInteger(hPipe)
' if the data is less than 1024 read it in now ..
If varLen < 1024 Then
bytesRead = varLen
ReadFile(hPipe, varData(0), varLen, bytesRead, Nothing)
End If
' handle this variable
ProcessVariable(hPipe, varName, varData, varLen)
'***********
CheckAndTransmitDataPacket(com1) ' just loop trying to send packets
'***********
Loop
' termination signal -1 on attribute length
If varLen < 0 Then Exit Do
' process image
Process()
' Write out the processed image back to RoboRealm using stdout.
' You can also write back any other variables to use in
' other parts of the program.
' The format is the same as the input.
ReturnBytesVariable(hPipe, CStr("image"), imagePixels, CLng(imageWidth) * CLng(imageHeight) * 3)
' Send back the count as an example of how to feed back variables into RoboRealm
ReturnIntVariable(hPipe, "count", imageCount)
' write out end of message
WriteFile(hPipe, ASCII.GetBytes(""), 4, bytesWrite, Nothing)
FlushFileBuffers(hPipe)
If bytesWrite <= 0 Then Exit Do
' continue by waiting for next image request
Loop
'=========== VB Pipe Loop end==========
End While
XBeeTransNotReady(com1) ' send out a not ready in case it was waiting for us
End Using
End If
CommThread.ReportProgress(99)
End Sub[/code]
There is alot more code added, but this is the main essence… The image data like the cog information are handled in the ProcessVariable sub. I used the VB.net plugin files found here. Maybe there should be another “CommThread” for handeling the Pipe part too? At the moment most of the code are way over my head but I’m trying to keep my neck over the water though.
So to make the Roborealm connection to work the XBee connection needs to be activated (means that I’ve to hit the “connect” button within a short period of time after startup) .
Anyway, this was a really fun project to work with! I believe I’ve got to study VB a bit more.