arthur64 Posted Sunday at 01:50 PM Share Posted Sunday at 01:50 PM I'm working on a new project to control my hottub. I'm designing using a RasPi 3+ and an 8 chan relay board. I have a php function that does "$fd = fopen (/dev/ttyUSB0, w+) and fprint (fd, "0x%s", an octal string); and relay 1 turns on, turns off - as does 2 thru 8. on off on off on... life is good. My problem: Mfg info says 0xFF will return the status of all 8 relays as in "00100110". I have tried all sorts of combinations of fprint 0xFF which seems to go OK. Then fgets, fscanf, fread and the code just hangs. Has anyone gotten this to work? Can someone offer some help? Thanks in advance. (I'll owe u a beer) Quote Link to comment https://forums.phpfreaks.com/topic/330335-lcus-8-usb-relay-module-8-channel/ Share on other sites More sharing options...
gizmola Posted Monday at 05:06 PM Share Posted Monday at 05:06 PM We would need to see some code, as well as a link to the documentation. One obvious thing to try would be to open the connection using "r+" instead of "w+". Quote Link to comment https://forums.phpfreaks.com/topic/330335-lcus-8-usb-relay-module-8-channel/#findComment-1658991 Share on other sites More sharing options...
arthur64 Posted 4 hours ago Author Share Posted 4 hours ago $oo = 0 for turn off / 1 for turn on $relay = 1 [...8] $on = array ("", "\xa0\x01\x01\xa2", "\xa0\x02\x01\xa3",... the second octet is the relay number, third is on/off, 4th cksum $off = array ("", "\xa0\x01\x00\xa1", "\xa0\x02\x00\xa2",... $fd = fopen ("/dev/ttyUSB0", "w"); switch ($oo) { case 0: fprintf ($fd, "0x%s", $off[$relay]); break; case 1: fprintf ($fd, "0x%s", $on[$relay]); break; } The above code works fine. Comm with mfg says 341 chip doesn't xmit only rec. ?? lost in translation. Web pages seem to say "0xFF" will return 01001000 - ???? Thanks for any help Quote Link to comment https://forums.phpfreaks.com/topic/330335-lcus-8-usb-relay-module-8-channel/#findComment-1659156 Share on other sites More sharing options...
gizmola Posted 3 hours ago Share Posted 3 hours ago I say again: did you try to fopen with "r+"? If you fopen with "w" that is write only mode, and you can't read from it. Quote Link to comment https://forums.phpfreaks.com/topic/330335-lcus-8-usb-relay-module-8-channel/#findComment-1659159 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.