Results 1 to 3 of 3
  1. #1
    F.S. is offline Member
    Join Date
    Feb 2012
    Location
    Bruges, BELGIUM
    Posts
    16
    Rep Power
    0

    Default 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:

    Java 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?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Variabel Parameters Serial Communication

    Use combo boxes for the three non-baud ones containgin the allowable options.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    F.S. is offline Member
    Join Date
    Feb 2012
    Location
    Bruges, BELGIUM
    Posts
    16
    Rep Power
    0

    Default 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 .

    For anyone in the future looking for this:
    -Declare integers:
    Java 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:
    Java Code:
    myPort.setSerialPortParams(Baud,dataBits,stopBits,Parity);
    Last edited by F.S.; 03-07-2012 at 11:57 AM.

Similar Threads

  1. Serial Communication
    By F.S. in forum Advanced Java
    Replies: 9
    Last Post: 03-06-2012, 08:07 AM
  2. Help with USB/Serial communication
    By Blackmore in forum Advanced Java
    Replies: 0
    Last Post: 08-16-2011, 09:45 PM
  3. Serial communication via ethernet-serial hub
    By Idiodyssey in forum New To Java
    Replies: 0
    Last Post: 05-04-2011, 03:23 PM
  4. Serial port Communication Problem
    By rjagan in forum New To Java
    Replies: 8
    Last Post: 04-20-2011, 01:36 PM
  5. Replies: 1
    Last Post: 07-30-2010, 09:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •