Variabel Parameters Serial Communication
Hello,
I have created a program that allows me to establish serial communication with a certain device. This device has the following properties:
-Baud Rate=9600
-1 stopbit
-8 databits
-No Parity
These parameters are set as followed:
Code:
myPort.setSerialPortParams(Baud,SerialPort.DATABITS_8,SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
I would like to adjust the program so that a user can adjust these properties from the form I created. Right now only the baud rate is variabel. Offcourse the easiest way is to create and if-elsif-...-else loop describing every possible combination, bu I can't imagine there is no more effective way to do this. Can anyone suggest me anything?
Re: Variabel Parameters Serial Communication
Use combo boxes for the three non-baud ones containgin the allowable options.
Re: Variabel Parameters Serial Communication
Found it. I didn't know you could just change the variabels by normal integers en declare those integers elsewhere. I thought it had to be done there.
Kind off stupid of me if you think of it now :(nod): .
For anyone in the future looking for this:
-Declare integers:
Code:
protected int Baud=9600, //Baud rate
dataBits=SerialPort.DATABITS_8, //number of databits
stopBits=SerialPort.STOPBITS_1, //can be 1, 1_5 or 2
Parity=SerialPort.PARITY_NONE; //set type of parity
-Set properties:
Code:
myPort.setSerialPortParams(Baud,dataBits,stopBits,Parity);