Python barcode scanner serial trigger - python

I'm messing around with a Honeywell 4600 barcode scanner in python, configured as a serial device. All is well and I can read barcodes with it, but I would like to test the serial trigger option instead of pressing the trigger all the time.
The manual is very brief on this feature and only states "SYN T CR" has to be written to the device to activate the serial trigger
ser.write('SYN T CR')
does not seem to do much.
Can someone point me in the right direction? Thank you!

This happens because you coded the abstract expression written in the document as raw output data.
The document represents 3 bytes of data transmission.
'SYN' and 'CR' are the following hexadecimal numbers.
'SYN' = \x16
'CR' = \x0d or escape sequence \r
'T' is an ordinary ASCII character.
Whitespace is used to separate the data in the document, not data to send.
You should write like this. Please try it.
ser.write(b'\x16T\r')
Alternatively, perhaps even you may need to prefix it.
Send data to Honeywell Xenon 1902 barcode reader via virtual com port
In that case, please try the following transmission.
ser.write(b'\x16M\r\x16T\r')

Related

Capture data sent to printer

I have a POS application running on windows machine which prints data and does not allows to save the data. I try to print to pdf but does not seem possible. I would like to capture the data send to the printer maybe from the USB port and then later convert it to human readable text. I am pretty new to this, so a detailed answer with all steps will be much appreciated. Also to note its a thermal printer, just so if it makes difference!

Syntax of MODBUS RTU commands

I have been trying to read data from a weather sensor using MODBUS RTU through the RS485 pins on a Raspberry Pi. I am having trouble recognizing the syntax of the commands that I have to write. On the pymodbus readme it says:
read_coils(address, count=1, **kwargs)
Parameters:
address – The starting address to read from
count – The number of coils to read
unit – The slave unit this request is targeting
I am not able to understand whether I should type in the address in Hex format or DEC format, I am also not able to understand what the parameter "unit" means.
In the datasheet of the weather station, the following values are given as register addresses but I don't know which values go into the command
Datasheet of weather station
Can anyone please tell me in which format I am supposed to write the address, and also what I should write in the "unit" field
Thanks in advance to this amazing community
The address is passed as an integer type (number). In Python, you can write a number in hexadecimal (e.g. 0x75fb) or in decimal (e.g. 30203) or even in binary (0b111010111111011). Whichever you prefer.
In Modbus, the term coil refers to a boolean output. You can set a coil to "on" or "off". You probably wanted read_input_registers() instead. You can tell by the address from your linked datasheet: 30001-39999 (in decimal) are input registers. You should read a bit about Modbus basics, e.g. the simplymodbus.ca FAQ has a table of address ranges.
The term "unit" is just a very bad and confusing name. I think it refers to the Modbus slave ID. You can have more than one slave ("units") on the same bus. You probably can configure it on your device, and the manual should tell you about it. For Modbus-RTU (not Modbus-TCP), if you pick the wrong number you'll get no answer. But keep in mind there are a hundred other possible reasons for why you might get no answer from the device.
It's best to have an oscilloscope in reach if it doesn't work, to check if your device is not sending or the other device is not answering or if the voltages are wrong. There is also a chance to fix problems "blindly", by double-checking everything you did, but it can be frustrating.

USB Serial data sending gibberish

i am having an issue i cannot seem to resolve. i am using python on the raspberry pi to read from a usb connection on the pi (that is being converted from serial).
i am able to connect to the usb port and start receiving data with the code
ser = serial.Serial("myUsbPortID", 9600)
bytes = ser.inWaiting()
print ser.read(bytes)
i know that the baudrate is 9600 (hardware manufacturers docs) but for some reason when i try to read the stream of data i get a lot of gibberish in the form of different languages and characters. After i kill the program my screen still replaces my characters with the gibberish data as i type.
i'm sure this isn't the stream of data the hardware is sending. something somewhere is converting things but i have no idea what it may be.
when i boot up the device and it is initializing then i get readable information. but when the device start operating i only get this weird characters
is there a way to convert these characters to the data that it is actually coming in as?
example pic:
output screen
so i was able to solve the issue of the gibberish with this line on python code (for anyone else having this issue).
data = ":".join("{:02x}".format(ord(c)) for c in bytes)
where bytes is the raw data, i'm making it ':' delimited.
seems the connection and baud rate was ok. luckily the data was able to convert to hex ok.

Python TCP socket for a lot of data

We (as project group) are currently stuck on the issue of how to handle live data to our server.
We are getting updates on data every second, and we would like to insert this into our database (security is currently not an issue, because it is a school project). The problem is here we tried python SockerServer and AsyncIO to create a TCP server to which the data can be sent.
We got this working with different libraries etc. But we are stuck on the fact that if we keep an open connection with the client (in this case hardware which sends data every second) we can't split the different JSON or XML messages. They are all added up together.
We know why because TCP only provides order.
Any thoughts on how to handle this? So that every message sent will get split from the others.
Recreating the socket won't be the right option if I recall correctly.
What you will have to do is ensure that there is a clear delimiter for each message. For example, the first 6 characters of every message could be the length of the message - whatever reads from the socket decodes the length then reads that number of bytes, and sends the data to whatever needs it. Another way would be if there is a character/byte which never appears in the content, send it immediately before a message - for example control-A (binary value 1) could be the leadin character, and send control-B (binary value 2) as the leadout. Again the server looks for these framing a message.
If you can't change the client side (the thing sending the data), then you are going to have to parse the input. You can't just add a delimiter to something that you don't control.
An alternative is to use a header that encodes the size of the message that will be sent. Lets say you use a header of 4 bytes, The client first send the server a header with the size of the message to come. The client then sends the message (up to 4 gigs or there about). The server knows that it must first read 4 bytes (a header). It calculates the size n that the header contained then reads n bytes from the socket buffer. You are guaranteed to have read only your message. Using special delimiters is dangerous as you MUST know all possible values that a client can send.
It really depends on the type of data you are receiving. What type of connection, latency... If you have a pause of 1 second between packets and your connection is consistent, you could probably get away with first reading the entire buffer once to clear it, then as soon as there is data available - read it and clear the buffer it. not a great approach, but it might work for what you need - and no parsing involved.

Encoding for ZMQ

I am currently doing project which requires communication from a PC to the device, so far I've decided on socket comms. and have written some code. I am also using ZMQ for ipc on the device itself.
My script works by sending data as text across. I was trying to encode my data to utf-8 so that it can be easily read on the device and displays in a frame and performs the tasks as needed. However, I can't seem to get the encoding working right, I've tried searching for examples or tutorials online but can't seem to find any.
I've tried using socket.send (msg.encode("UTF-8")) to encode my data, and message = socket.recv() to recv & print the data on the server. This works but the server would print out the exact text data which is not what I wanted. I'm unsure whether this is the correct way, and hope that someone could point me in the correct direction for encoding & printing the encoded data without decoding back to text.
You are receiving the text as encoded UTF8 data. It is all working correctly.
However, if you are printing the data on the receiving end directly to a terminal that happens to be configured to display UTF-8, you won't see any difference.
Print the representation instead:
print repr(message)
to see the string literal representation including any non-printable, non-ASCII bytes displayed as escape strings.

Categories