Jump to content
  • 0

Waveforms SDK trouble reading from SerialPort


The_YongGrand

Question

Hello Digilent support,

I'm using the Waveforms 3.21.2 SDK and struggling to get the SerialPort module to at least read the string that is received from another microcontroller board. 

 

This microcontroller board's serial is using the USB CDC and it is a generic Raspberry Pico board. It is connected to the PC like any other serial ports.

 

For example, here's the code:

var com = new SerialPort();

// wait for the com port to be available:

while(!com.open("COM6",115200)) {}

// The microcontroller board sends a string example: Hello World to the PC after the board is detected and printed on the output:

print(com.read());

However it doesn't read anything - not sure if I missed out something there. Also, any more examples of the SerialPort for the SDK, especially reading strings?

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Hi @The_YongGrand

This is the Script tool and not the SDK.
The serial port communication is relatively slow so some wait is needed, like com.open(),wait(seconds),com.read() or com.read(seconds) or com.canReadLine()...
In Script loops use wait() to be able to stop it correctly, the while(!com... could block the script.
Try the following:

var list = SerialPortList(); // returns: [name 1, description 1, name 2, desc 2, ...]
for(var i = 0; i < list.length; i+=2){
    print(list[i]+" : "+list[i+1])
}
if(list.length){
    print("Sending Hi to "+list[0])
    var com = new SerialPort();
    if(!com.open(list[0], 115200)) throw "COM open failed"
    com.write("hi\n");
    while(wait()){ // while not stopped
        if(com.canReadLine()){
            print(com.readLine());
        }
    }
}

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...