السلام عليكم
اريد معرفه كيفيه التحكم بال sereal ports مثل ال com , usb
وياريت اعرف هذا الموضوع يدعمه اي اصدار من الجافا
هل هو J2EE OR JSDK
وماهي ال CLASSES المستخدوه او ال PACKAGE
وذلك للاهمية لاني اعمل على هذا المشروع
ولكم جزيل الشكر
السلام عليكم
اريد معرفه كيفيه التحكم بال sereal ports مثل ال com , usb
وياريت اعرف هذا الموضوع يدعمه اي اصدار من الجافا
هل هو J2EE OR JSDK
وماهي ال CLASSES المستخدوه او ال PACKAGE
وذلك للاهمية لاني اعمل على هذا المشروع
ولكم جزيل الشكر
بالنسبة لليو اس بي فقد بحثت عن هذا من قبل وتبين بان مكتبة الجافا J2SE and J2EE لا يوجد بها دعم لليو اس بي ولكن هنالك بعض الشركات تقدم حلول وكلاسات جاهزه لهذا الغرض و منها :
ويمكنك قراءة المزيد من هذين الموقعين
اما بالنسبة للCOM فاستخدم هذا الباكج : javax.comm
وهنت مثال عن 2 كلاسس باستخدام هذا الباكج
SimpleWrite.java
________________________________________________
import java.io.*;
import java.util.*;
import javax.comm.*;
public class SimpleWrite {
static Enumeration portList;
static CommPortIdentifier portId;
static String messageString = "Hello, world!\n";
static SerialPort serialPort;
static OutputStream outputStream;
public static void main(String[] args) {
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
// if (portId.getName().equals("COM1")) {
if (portId.getName().equals("/dev/term/a")) {
try {
serialPort = (SerialPort)
portId.open("SimpleWriteApp", 2000);
} catch (PortInUseException e) {}
try {
outputStream = serialPort.getOutputStream();
} catch (IOException e) {}
try {
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
try {
outputStream.write(messageString.getBytes());
} catch (IOException e) {}
}
}
}
}
}
________________________________________________
SimpleRead.java
________________________________________________
import java.io.*;
import java.util.*;
import javax.comm.*;
public class SimpleRead implements Runnable, SerialPortEventListener {
static CommPortIdentifier portId;
static Enumeration portList;
InputStream inputStream;
SerialPort serialPort;
Thread readThread;
public static void main(String[] args) {
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
// if (portId.getName().equals("COM1")) {
if (portId.getName().equals("/dev/term/a")) {
SimpleRead reader = new SimpleRead();
}
}
}
}
public SimpleRead() {
try {
serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
} catch (PortInUseException e) {}
try {
inputStream = serialPort.getInputStream();
} catch (IOException e) {}
try {
serialPort.addEventListener(this);
} catch (TooManyListenersException e) {}
serialPort.notifyOnDataAvailable(true);
try {
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
readThread = new Thread(this);
readThread.start();
}
public void run() {
try {
Thread.sleep(20000);
} catch (InterruptedException e) {}
}
public void serialEvent(SerialPortEvent event) {
switch(event.getEventType()) {
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer = new byte[20];
try {
while (inputStream.available() > 0) {
int numBytes = inputStream.read(readBuffer);
}
System.out.print(new String(readBuffer));
} catch (IOException e) {}
break;
}
}
}تم تعديل هذه المشاركة بواسطة مجدي محمود في 27 أكتوبر 2004 في 16:37
TheActionTime@hotmail.com
اخي الكريم شكرا لاهتمامك ......
لكن ياريت لو عندك ايه معلومات بخصوص ال USB وكيفية برمجتها
تخبرني عنها لاني محتاجها ضروري
وجزاك الله خيرا
وانا عندي حل الـ com و الـ LPT
اذا اردت اعطيك ياهم.. حيث قمت بالبحث بهذا الموضو عمنذ فترة طويلة
تستطيع البحث بالمنتدى و سوف تجد الكثير من المناقشات
Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why
الاخ رامي :-
ياريت لو تساعدني بخصوص ال usb
تحت اي نظام linux or windows لا يهم المهم اريد ال باكج الخاصة ب usb
وذللك للضرورة
ولك جزيل الشكر
و الله انا ما عندي خبرة باليو اس بي
بس بغيره بحسن افيدك
Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why
الاخ رامي :-
لو عند فكره عن ملفات jin or jni والطريقه لربط الجافا بالسي ياريت تخبرني
وشكرا
هذا الموضوع مغلق.