Read Serial Port Powerbuilder

Read Serial Port Powerbuilder Rating: 7,2/10 7487 votes
Serial

I need to know how I can continuously read data in from the COM port and dump it to a file using Windows Powershell. While I am reading data in, I also need to monitor the data being read in and, depending on what the last line that was read, write data to the COM port.To open the COM port in Powershell, I am doing this: System.IO.Ports.SerialPort::getportnames$port= new-Object System.IO.Ports.SerialPort COM3,115200,None,8,one$port.openTo read data in to the COM port, I am doing this: $line=$port.ReadLineMy initial thought was to have the main Powershell script open the COM port. Then it would start a background/child task to continuously read data in from COM port and dump it to a file.

While that child task is running, the parent would then continuously monitor the file and write to the COM port when needed.When I tried to do that, the child could not read data in from the COM port because the parent had it open and the child did not inherit that permission from the parent.Any ideas on how I can accomplish this?

Powerbuilder Read Serial Port

Hi,guys I need to use matlab to read and write serial port for getting data from my MCU. But actually the code is not efficiently in that I have to add a line 'pause (1);' in the code to make the code run well. If I do not, the code cannot read data later. Jack - Perhaps you can make use of the second return parameter from which returns the number of variables read: A,count,msg = fread(.) returns the number of values read to count, and a warning message to msg if the read operation was unsuccessful. Is it safe to assume that once the start variable is read successfully, then those that follow should be available too? If so, then you could try the following. Remove the pause(1) that you added, and replace start=fread(s,1,'uint16'); with% declare a 10 millisecond delay delaySec = 0.01;% read from the serial port start,varcount,msg = fread(s,1,'uint16');% keep reading until the start data is returned while varcount0% pause pause(delaySec);% try again start,varcount,msg = fread(s,1,'uint16'); end The above will continue to read from the serial port until some data is returned.

A problem is getting stuck in the while loop if no data is ever going to be sent again. To get around this, you could put a cap on the number of iterations in the while loop.% declare a 10 millisecond delay delaySec = 0.01;% if more than 10 seconds have passed without data, then exit maxIters = 10/delaySec;% use to keep track at which iteration we are at atIter = 1;% read from the serial port start,varcount,msg = fread(s,1,'uint16');% keep reading until the start data is returned while varcount0 && atIter.

Read Serial Port Powerbuilder

Hi, I have tried your method,but it seems it doesn't work.I replace start=fread(s,1,'uint16'); with start,varcount,msg=fread(s,1,'uint16'); while varcount0 pause(0.1); start,varcount,msg=fread(s,1,'uint16'); end but it cannot work. - - - - - - - - - - - - - - - the function fread, if there is no data, will finish until the Timeout(10s by default); In my former code, If I add 'pause(1);', the next 'start=frea(s,1,'uint16')' can receive data;but if I do not, the next 'start=fread(s,1,'uint16')' have to wait for data for about 10s. This 10s here is longer than the 1s in 'pause(1);'. Theoretically,It will receive some data,but actually it receives nothing. In your code, enven if I change pause(0.1) to pause(2),it doesn't receive anything. The line 'start,varcount,msg=fread(s,1,'uint16');' still have to wait for 10s if no data input.

I don't know what's wrong with my matlab code, it is very weird. 1s here work,but 10s in another place does not work any more.