Our app receives data from a digital scale after we issue the port.read command. When the scale is outputting continuous streaming data, we use the following syntax that works fine:
pswork1 = objPort.Read(20, 10000)
It apparently keeps on reading until it has encountered 20 bytes and moves on down through the rest of the code, just as expected.
But we are having problems when we are reading from a scale that outputs data on demand (like by pushing the print button on the scale or sending the scale a request character), where the scale outputs one string of data approx. each minute or so. We've tried to use the following syntax:
pswork1 = objPort.Read("", psTrigger, 10000)
where 'psTrigger' might have a value of ascii 013, to represent a carriage return.
In some cases this works fine every time. In other cases it does not work right at all, and yet other cases it is intermittent, i.e. it works sometimes, and other times produces invalid data in pswork1.
For example, last week I was trying to set up for a new scale install, but I never could get it deliver all 20 bytes of data. It DID read data based on the trigger value, and I know that because it did not wait around for 10 seconds to timeout. Instead, it immediately finished doing it's read as expected, and went on down into the program showing me that pswork1 was only two bytes long, rather than 20 bytes like I sent it (where byte 20 is an 013). And, there definitely was only one 013 in the data string, so that can't be the problem.
Am I doing something wrong here? Anything I can try? Am I correct in thinking that it's supposed to keep trying to read data until it encouters the EndTrigger value, or the timeout time--whichever comes first? TIA