Author Topic: TINIm400 serial reading  (Read 15316 times)

TOMOYO

  • Member
  • ***
  • Posts: 5
TINIm400 serial reading
« on: March 14, 2011, 05:53:32 am »
Hi guys,
I'm currently working on a project with a TINIm400 board, in order to get datas from sensors by RS232, and transmit them to a server by Ethernet.
The main issue is that regarding the age of this board, I can't find any interesting source code which could help me to code that in java.

Here is a sample of what i coded, I'm testing this with a GPS, so basically receiving NMEA frames by RS232.

Code: [Select]
import java.io.*;
import java.util.*;
import javax.comm.*; //Utilisation de l'API javax.comm

public class LectureSerie {

//declaration des variables
static CommPortIdentifier portId;
static Enumeration portList;//Liste des ports série de la carte
static InputStream in;
static SerialPort serialPort;
//boolean inputBufferEmptyFlag;
// buffer de lecture
static byte[] data = new byte[10];

public static void main ( String [] args){


int i=0;
boolean flag=false;
boolean portFound = false ;
String defaultport = "serial0"; // port serial0 est le port par défaut

//aucun argument passé dans le tableau args
if (args.length >0){
defaultport= args[0];
}

portList = CommPortIdentifier.getPortIdentifiers();//renvoi les ports de la machine

while (portList.hasMoreElements()){
portId = (CommPortIdentifier) portList.nextElement();//nom du port à utiliser
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL){
if (portId.getName().equals(defaultport)){
System.out.println("Port serie trouve :" + defaultport);//port trouvé
portFound=true;
try{
serialPort=(SerialPort) portId.open("AppLectureSerie",5000); //ouverture du port
System.out.println("Port serie ouvert");
}catch(PortInUseException e) {
System.out.println("Port deja utilise.");//si port actuellement utilisé, gestion d'exception
continue;
}
try{
//récupération du flux d'entrée
in = serialPort.getInputStream();
}catch(IOException e) {}
try {
serialPort.setSerialPortParams(115200, SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);//configuration du port
System.out.println("Port serie configure");
}catch(UnsupportedCommOperationException e) {}

System.out.println("Ecoute du port serie");
try{
//Tant qu'il y a  des octets dispo
while (i<10) {
System.out.println("ligne : " + (i+1) );
int flux = in.read(data);
//afficher le nombre d'octets transmis
System.out.println("| nb octet lu : " + flux +" | ");
System.out.println("| contenu tab : " + data[i]+"  | " );
System.out.println("-----------------------");
i++;
}
}catch(IOException e){}
flag=true;
//fermeture du port série
if (flag){
System.out.println("Fermeture du programme");
//serialPort.close();
System.exit(1);
}
}
}
if (!portFound){
System.out.println("port " + defaultport + " non trouve");
}
}
}
}





Thanks to this code, I get some datas [ weird characters ] but they're emitted randomly, the gps sends it every second but the board doesn't screen it regularly.

In fact, my final objective is to get this : SENSORS -> RS232->TINI->ETHERNET->SERVER

Any idea ? I'm a bit lost.

I also have a little question about the fact serial server stops and starts, what's happening in fact?

Thanks for your help.

Sofiene HAMMAD
« Last Edit: March 14, 2011, 09:51:23 am by TOMOYO »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: TINIm400 serial reading
« Reply #1 on: March 14, 2011, 04:18:54 pm »
Get the serial and Ethernet interfaces working separately (do a loopback application to test), then put them together.

These might help:

http://www.maxim-ic.com/products/tini/devguide.cfm

http://www.janaxelson.com/eeccode.htm

Jan
« Last Edit: June 27, 2015, 09:47:22 am by Jan Axelson »

TOMOYO

  • Member
  • ***
  • Posts: 5
Re: TINIm400 serial reading
« Reply #2 on: March 15, 2011, 05:43:18 am »
Hello,
 thanks for the links, unfortunately I already found them.

I tried something like that :  TINI card is plugged to a PC by RS232 communication via hyperterminal, and also linked by ethernet to a telnet session. Thing is, if i turn on hyperterminal telnet session stops. And I don't understand this.

edit : I found what I wanted most likely with the CommTester example provided by tini firmware.
But I meet some errors at the compilation, am I supposed to change some parts of the code? It was supposed to be working as soon as I pasted it on my computer and got so much problems.

What's the best thing to use? I'm only working with the dos console of windows.

Sofiène HAMMAD
« Last Edit: March 15, 2011, 09:20:35 am by TOMOYO »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: TINIm400 serial reading
« Reply #3 on: March 15, 2011, 10:49:01 am »
This forum archive might have something useful:

http://osdir.com/ml/hardware.microcontrollers.tini/

Jan

TOMOYO

  • Member
  • ***
  • Posts: 5
Re: TINIm400 serial reading
« Reply #4 on: March 21, 2011, 10:27:39 am »
Hi, I understood a few things thanks to the link you gave me, after analyzing the SerialToEthernet code, I decided to use it since it fits perfectly to my project. However I meet some short issues at the execution such as :

- When I do it by netbeans : the java application doesn't find the TINI card, and it's stuck to " waiting for connection"
- When I try to do it by DOS by typing : java serialtoethernet.Serial COM1 , it gives me a classpath problem i guess but i don't have a clue to solve it :

Code: [Select]
java Serial
Exception in thread "main" java.lang.NoClassDefFoundError: Serial (wrong
name:
serialtoethernet/Serial)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)



Thanks in advance
regards sofiène HAMMAD
« Last Edit: March 22, 2011, 09:45:42 am by TOMOYO »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: TINIm400 serial reading
« Reply #5 on: March 23, 2011, 09:59:29 am »
A java forum like:

www.coderanch.com/forums

might be able to help.

Jan