I am writing a program to send DALI commands via serial port. So, at this case, I got various problems. First of all, DALI commands are messages of 19 bits for questions (1 start bit, 8 adress bits, 8 command bits and 2 stop bits) and 11 bits for answers(1 start bit, 8 response bits, and 2 stop bits). The problem is the fact that with pyserial I can only send bytes via serial port, not bits, and, if I convert that bits to a byte, I need 3 bytes for a question and 2 for and answer with bits unused... How it's supposed to do that. Is there any way to send bits one by one via serial port using pyserial?
Asked
Active
Viewed 2,540 times
1
-
in short i don't think what you want is possible as every byte sent out of a normal serial port will have a preceding start bit and trailing stop bit/s. so even if you stuff your "bits" into bytes that pyserial will send, you won't actually get what you want. the best i can suggest would be to "bitbang" what you want out of the computer by doing something like toggling the `DTR` line or similar. – James Kent Aug 18 '17 at 09:05
-
Ok, I'm new in this, I was searching what bitbang is. So, Serial port only work with RS232? – David González Blazman Aug 18 '17 at 09:11
-
depending on what hardware you have different protocols may be supported, such as RS485, 422, 423, 232 etc, but as far as i'm aware most if not all of these do the same thing with start/stop bits. the most common one fitted to computers or available with usb adaptors is 232, which definitely puts start and stop bits on the bytes you send. – James Kent Aug 18 '17 at 10:00
-
pyserial is able to use and "serial" devices that your computer may have, such as the UART output on the raspberry pi, but again i believe this uses start and stop bits, so no good for your usage. it seems like bitbanging is your best course of action – James Kent Aug 18 '17 at 10:01
-
do you know what baudrate is required? and i say bitbanging through serial port (although will need to make your own cable) is easiest as you won't have to make any custom drivers, alternatively you could use and arduino to do the bitbanging, and send the data to it through the serial port it presents to the pc. btw bitbanging is very cpu intensive as it cannot be offloaded to dedicated hardware – James Kent Aug 18 '17 at 10:03
-
Ok, I know, the baudrate is set to 1200 and it have bi-phase manchester encoding, that's the reason I ask you about the RS232. I think that RS protocols implement start and stop bits in every byte you send by default, I can't implement a way to send my chains of 19/11 bits encoded in Manchester because of the default implementation of the rs protocol in serial port... – David González Blazman Aug 18 '17 at 10:12
-
am i reading the spec right that bi-phase manchester encoding needs idle at middle of voltage range, and a high and a low, so three voltage states? – James Kent Aug 18 '17 at 10:31
-
I think that it have only 2 states, high and low, high over 9.5v and low down to 6.5v, the start bit is a logical one, and the last two bits, that are the end bits are physical ones, that I think are two high voltage states over 9.5v – David González Blazman Aug 18 '17 at 10:37
-
ok well you'll need to implement your own circuit to levelshift to the right voltage, but i think i can cobble something together (won't be able to test it) that might work, at least for writing, without anything to test reading back may be too difficult to write – James Kent Aug 18 '17 at 10:43
-
For this project, I am using a PIC16F1947 and a AN1465 Dali Adapter. First of all, my friend is trying to know how it works the PIC, the next step is the DALI communication. Philips got a program that is a DALI sniffer and I can know if the DALI message is correctly sent. – David González Blazman Aug 18 '17 at 10:58
-
So the first step is to send this message vía Python to the DALI interface and use the sniffer to see if the message is correct. And the next step is use the PIC to send the same DALI command and see if its correct. – David González Blazman Aug 18 '17 at 11:00
-
So, my friend and I are trying to understand how ti works the pic to fix the right voltage to the bits sent... It's a very difficult way to mantain a communication – David González Blazman Aug 18 '17 at 11:01