Please check the HIDAPI classes for doing this cross platform:
Please check the HIDAPI classes for doing this cross platform:
On Mac it works well with the HIDAPI classes. I transfer the same memoryblock through HIDAPIDeviceMBS.SendFeatureReport and receive back an "8" from Mac.
On Windows however I supposed it would work the same, however it returns me a "-1" as soon as I transfer the same memoryblock. Whether using HIDAPIDeviceMBS.SendFeatureReport or HIDAPIDeviceMBS.Write makes no difference.
Any idea what I should do differently for Windows applications?
I think Windows is more picky about the block sizes.
So can you ask for Report size and than make sure your block matches?
and block may need to be 1 bigger to put the report ID in the first byte:
// Send a Feature Report to the device
dim buf as new MemoryBlock(17)
buf.UInt8Value(0) = 2 // First byte is report number
buf.UInt8Value(1) = &ha0
buf.UInt8Value(2) = &h0a
dim r as integer
r = d.SendFeatureReport(buf)
It is working now since - as you said - Windows expected an extra byte upfront. The solution below works well for Mac and Windows with the HIDAPI Class.
dim res as integer
dim mb as New MemoryBlock(9)
mb.byte(0)=0 'always 0
mb.byte(1)=255 '255: single on, 253: single off, 254: all on, 252: all off
mb.byte(2)=1 'relay number (1-8)
I recently purchased what looks like the same relay-board module , so I was glad to see this conversation since mine has absolutely no specs or info with it.
I have not been successful in getting any kind of response from the board, aside from illuminating the USB LED on the board. When I unplug and re-plug the USB cable, I can hear all of the relays activating, so I'm pretty confident that it's alive and well. Also, it's pretty clear that this board is using COM5.
So here are my questions: am I supposed to have some sort of additional driver or the like, such as MacHIDMBS PlugIn that was mentioned in the initial posting or is the Xojo Serial control enough? I'm running on Windows, so I don't have an option to use that. Is there a Windows version? Is it necessary when using the Xojo "Serial" control?
Regarding my code, I'm using the following (BTW, my Serial control is named TestSerial, which I hijacked from another Xojo example program):
In the Window "Open" event, I execute the following code:
TestSerial.SerialPort = System.SerialPort( SerialPortPopup.ListIndex ) 'this is also from the hijacked code... 'Communication Parameters: '8 Data, 1 Stop, No Parity 'Baud rate : 9600 TestSerial.Bits=Serial.Baud9600 TestSerial.Stop=Serial.StopBits1 TestSerial.Parity=Serial.ParityNone TestSerial.Baud=Serial.Baud9600
I've placed the following code in the "Action" event of a push button control... I've tried many variations of it, but this is pretty much what I've learned from this conversation. Please let me know where I've erred or if there's something more that I need to do.
Dim mb as new MemoryBlock(4) dim res as integer 'Initialize the communication with the module mb.byte(0)= &h0 mb.byte(1)=&h50 '255: single on, 253: single off, 254: all on, 252: all off mb.byte(2)=&h51 'relay number (1-8) mb.Byte(3)=&h0 TestSerial.write(mb) TestSerial.flush 'Attempt to turn on all relays mb.byte(0)= &h0 mb.byte(1)=&h252 '255: single on, 253: single off, 254: all on, 252: all off mb.byte(2)=&h1 'relay number (1-8) - another bump to try to turn on relay 1 mb.Byte(3)=&h0 TestSerial.write(mb) TestSerial.flush
I would greatly appreciate any help that you could offer - my autopilot lawnmower hangs in the balance! Thanks in advance for your help,
Yes, the following code executes successfully and COM5 is added to the popup listbox when the code is executed. That would lead me to believe that it is a serial device. Is that a reasonable assumption?
// Populate the popup menu with all of the // serial ports the system has installed. Dim count As Integer count = System.SerialPortCount For i As Integer = 0 To count - 1 SerialPortPopup.AddRow( System.SerialPort( i ).Name ) Next
The project that I have mentioned, several times, is from Xojo's Example Projects, Communication, Serial. I have been adapting the project for my needs as you suggested, but it is still not producing any results, which was my reason for joining this conversation.
Is there any way to tell if the commands that I've issued are actually being transmitted?
Thanks for the "Good luck" wishes, but I would certainly appreciate some real help.
Thanks, Derk. I will experiment with the baudrate settings to see if they might make a difference.
Christian, please allow me to apologize for being somewhat curt and presumptuous of your help. I do appreciate the suggestions that you made and should not have presumed on your kindness for further help. Sincere apologies!
The FTDI device acts as a virtual Com Port (VCP). Both Macintosh and Windows have built-in VCP drivers, that usually work fairly well with the FTDI chip, though the VCP driver in older versions of these operating systems were not as good. FTDI has their own driver that you can download, and it usually works better with their devices than the older OS built-in drivers.
Another thing to consider is that short chunks of data may sit in a buffer somewhere and not get sent to the device. (It sometimes appears that the OS waits for a minimum amount of data before it sends it out.) You can force it to be sent by following your serial.write command with a serial.flush command.
Thanks for the info. I've been following the write commands with flush commands, so I think the problem is deeper than that. I checked the link that you posted, but once again, that puts me in new territory. I've done API calls from VB 6, but not Xojo, so I will have to do some homework & experimenting to make that work.
Here's a rookie question for you: Is it necessary to install the FTDI driver or does the Xojo Serial control handle that? Obviously, I have not done that, which may be the root of my problem.
In theory, it shouldn't be necessary to install any additional drivers, because the FTDI chip acts as a virtual com port (VCP) and the computer OS has a VCP driver built in. Somewhere on the FTDI website they state that the drivers on Windows 10 are compatible with their chip as are the current MacOS drivers. Apparently, the VCP drivers on earlier versions of MacOS and Windows had some issues. It was a few months ago when I found that comment, but I can't locate it now.
Where I found problems with the standard OS drivers was with their handling of RTS/CTS and DSR/DTR flow control. I wasn't able to get that to work until I changed to the FTDI driver. If your relay module requires the use of hardware handshake signals, then the driver could be the problem.
If you decide to install the FTDI driver, you don't have to make any changes to Xojo or your Xojo program. The new driver simply replaces the existing one, and it's completely transparent.