![How To Read A Weight Scale Via Serial Port How To Read A Weight Scale Via Serial Port](/uploads/1/2/4/8/124810495/384834317.jpg)
Posted by3 years ago
Archived
How to Connect an Electronic Balance or Scale to a PC and Read Weight Values Directly into Excel. Most electronic scales and laboratory balances have an RS2. RS232 question - how to read weight. I happen to have some code that reads from such a scale: // where this.port is an. How to Read and Write from the Serial.
Hi everyone! I'm extremely new to Powershell and I'm trying to figure out if I can do this:
Basically I have a PC connected to a scale head via serial connection on a COM port setup as a continuous stream of data. It's just sending the current weight on the scale probably about every half second as long as it's powered on. I'd like to be able to tap into that stream and grab the current weight in order to then send it to an IP camera as a text overlay (the camera has an HTTP API for that). I believe once I get the weight parsed correctly I can send it using an Invoke-Webrequest, but I'm having issues getting the data in the first place.
I've looked up some information about reading from serial ports (https://blogs.msdn.microsoft.com/powershell/2006/08/31/writing-and-reading-info-from-serial-ports) and it seems like it's possible, but after testing it very quickly it appears Powershell is hanging when I'm opening the port. I issued the commands directly into a Powershell command line and not a script. I'm thinking that since it's a continuous stream I can't access it while it's in use or that I need to create a script and tell it to close the port after a certain period of time.
Does anyone have any experience with this or can point me in the right direction? I'd hate to have to buy a piece of software to sniff the COM port, output it to file, and then parse the file if I can do it all within Powershell.
Update:
I ended up finding a product to create a virtual COM port to act as a splitter to allow multiple applications to access it (http://www.eterlogic.com/Products.VSPE.html). I then parsed the current weight from the COM port buffer and fed it to the camera using their HTTP API - all in a tiny script! Powershell is pretty cool. :)
Basically I have a PC connected to a scale head via serial connection on a COM port setup as a continuous stream of data. It's just sending the current weight on the scale probably about every half second as long as it's powered on. I'd like to be able to tap into that stream and grab the current weight in order to then send it to an IP camera as a text overlay (the camera has an HTTP API for that). I believe once I get the weight parsed correctly I can send it using an Invoke-Webrequest, but I'm having issues getting the data in the first place.
I've looked up some information about reading from serial ports (https://blogs.msdn.microsoft.com/powershell/2006/08/31/writing-and-reading-info-from-serial-ports) and it seems like it's possible, but after testing it very quickly it appears Powershell is hanging when I'm opening the port. I issued the commands directly into a Powershell command line and not a script. I'm thinking that since it's a continuous stream I can't access it while it's in use or that I need to create a script and tell it to close the port after a certain period of time.
Does anyone have any experience with this or can point me in the right direction? I'd hate to have to buy a piece of software to sniff the COM port, output it to file, and then parse the file if I can do it all within Powershell.
Update:
I ended up finding a product to create a virtual COM port to act as a splitter to allow multiple applications to access it (http://www.eterlogic.com/Products.VSPE.html). I then parsed the current weight from the COM port buffer and fed it to the camera using their HTTP API - all in a tiny script! Powershell is pretty cool. :)
10 comments
How To Read A Weight Scale Via Serial Port
I need some help trying to capture a weight on a scale that is hooked to the PC via a COM port. Reading a scale through a com port. The serial port then. May 10, 2012 First you have to create a separate method to be called to take weight. Then you have to fill the code in event handler. Following is. Oct 09, 2013 The first one might be suitable to continuously read data from a scale. But any serial port data receiving procedure is highly dependant on the form of the data that is being sent, and this varies enormously between devices, from simple text sequences as per the first example to complex binary data streams.