8 Channel USB Relay with MacHIDMBS

  1. ‹ Older
  2. 3 months ago

    Christian S

    Aug 13 Pre-Release Testers, Xojo Pro Germany

    Great!

    Please check the HIDAPI classes for doing this cross platform:
    http://monkeybreadsoftware.net/pluginpart-hidapi.shtml

  3. Thanks, Christian!

    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?

    Thank you,
    Julian

  4. Christian S

    Aug 14 Pre-Release Testers, Xojo Pro Germany

    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)

  5. Thanks, Christian!

    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)
    res=wDevice.SendFeatureReport(mb)

  6. 8 weeks ago

    Hi Everyone,
    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,
    Don

  7. Christian S

    Sep 22 Pre-Release Testers, Xojo Pro Germany

    How does device register with system?
    Does it sign up as serial device or as HID device? Or something else?

  8. Christian S

    Sep 22 Pre-Release Testers, Xojo Pro Germany

    Does it show up in System.SerialPort list?

  9. 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
  10. Christian S

    Sep 22 Pre-Release Testers, Xojo Pro Germany

    yes. So try Serial control.

  11. The control is the Serial control (it's the control that looks like a USB plug in the library). Is my code using something that conflicts with that? I'm in unfamiliar territory here, so I would greatly appreciate any direction you could give.
    Thanks

  12. Also, the relay module has an FTDI chip, which implies serial communication.

  13. Anybody home???

  14. Christian S

    Sep 23 Pre-Release Testers, Xojo Pro Germany

    Take example app for serial control and adapt it for your needs. Good luck!

  15. 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.

  16. Derk J

    Sep 24 Pre-Release Testers, Xojo Pro
    Edited 8 weeks ago

    Try a different baudrate like 115200 or 57600.
    Probably a settings thing in the serial class.

    Also i always make subclasses for serial, which might help

  17. 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!

    Take care,
    Don

  18. 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.
    http://www.ftdichip.com/FTDrivers.htm

    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.

  19. Hi Robert,
    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.

    Thanks much.

  20. 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.

  21. Great - I will give it a try.
    Thanks!
    Don

or Sign Up to reply!