I can get an 8 channel relay card on EBay for less than I would spend for the relays and the TTL to RS232 cards I've used are around $3. A little research will get you setups that someone has had working, and the cost needn't be much more that your bare chip, maybe less. These days, I'm usually happy with anything that works. Once you get your code working then you can hack hardware to your heart's content. There needs to be receive/transmit management and these are sorted out for the more popular paths. Starting with something that has been known to work helps limit the variables. It might be helpful to try a $12 USB to RS485 converter or the even cheaper TTL to RS485 converters from EBay. I can't promise anything, cause it's been a while now, but if I can find the lash-up I was using, I'll post a URL. I looked at MinimalModbus and PyModbus and they seemed like way overkill for as you say, one register. I think I used some free code posted by someone with the same goals. Given that AB seems to only grudgingly support Modbus, I would expect that you will need to be spot on to make things work. Not at all impossible, but certainly non trivial. It is not simple to meet all the requirements of modbus rtu. I'm not sure, but there are probably issues with your approach, not the least of which is you are either going to have to "fake" modbus or write at least a minimal Modbus master implementation and set the PLC up as a slave. I've been in electronics since the 70's and computers only a little less than that time and rather than start with a simple data transceiver chip, I would empt for something supported by Raspian and/or user experience. Hopefully you can find someone who has fought the thunderstorms and charged into the trees. Pushing to cloud via web services or JSON RPC is a lot fussier, and if you want some GUI, then I'm no help at all, as I've been a middle-ware guy - take data from device A, tweak the form, and push it off to device B. What you do with the data AFTER obtaining via Modbus is likely a dozen times harder than the Modbus. Use the Python 'struct' module to convert the binary to floats, as it handles big-endian. So using a power meter as example, I'd have a few 'refresh' routines which go out and pull a large block from modbus (read a range of registers) and save in memory, then a collection of 'get_total_kwh' (etc) which peels off the one data point of interest. This allow you to expand function without changing code. I tend to pass in parameters via dictionary (aka: keyed data or name-indexed array). If your goal is to pull a dozen data points from a device and NOT to create a public tool, then design isn't very important. On a resource-rich system, you can do anything in Python & its fast - on a small system, you have to be a bit more careful to do things effectively. If you are a traditional programmer, it can be mind-bending & annoying (I've used Python since 2002). If you DO NOT know C, then Python is fairly easy to learn. Hmmm, now "how to learn python" is a very different question - I see my Python Modbus RTU CRC post above is ten years old! My how time flies. > structure/layout? or am I way out of my league? > I'm very new to this and wouldn't know where to begin with Print "testing DF1 messages with crc16.py" Print "testing Modbus messages with crc16.py" # given a Byte, Calc a modbus style CRC-16 by look-up tableĬrc = (crc > 8) ^ table # crc16_Init() - Initialize the CRC-16 table (crc16_Table) Here is my CRC16 routine including a few test cases (written with no regard for CPU speed, since that is not why one uses Python). Other than that, look at the spec at for details of the actual protocol. You use lots of "chr(x)" function to build up a binary string and to parse a binary response lots of "ord()". The "Vaults of parnassus" is another nice source for Python toolsĬreating binary messages is not hard in Python, but a bit ugly. A web search of pyserial will turn up a download site - such as. For serial, you'll need some serial tool like pyserial - this hides details of OS and allows Linux (or Windows) style serial calls on either OS. I am not sure what your question is - I have lots of python code but it is far too much to offer as is.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |