Communicating jsp with serial port
Hi, I'm developing an web application that needs to communicate with Serial port. I'm not getting how to communicate with Serial port. I'm building application using jsp. Any one help me Please...
package serialio;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.TooManyListenersException;
import javax.comm.CommPortIdentifier;
import javax.comm.PortInUseException;
import javax.comm.SerialPort;
import javax.comm.SerialPortEventListener;
import javax.comm.SerialPortEvent;
import javax.comm.UnsupportedCommOperationException;
* @author SASH
public class SimpleWrite
implements Runnable, SerialPortEventListener {
public String line = "";
public String line1 = "";
public String text1 = "";
public String text2 = "";
public void run() {
static Enumeration portList;
static CommPortIdentifier portId;
// static String dest = "0517111930";
static String messageString = "Hello";
InputStream inputStream;
static SerialPort serialPort;
static OutputStream outputStream;
public void serialEvent(SerialPortEvent event) {
switch (event.getEventType()) {
case SerialPortEvent.DATA_AVAILABLE: {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
try {
while ((line = reader.readLine()) != null) {
arata(line);
// System.out.println(line);
} catch (IOException e) {
System.err.println("Error while reading Port " + e);
break;
} //switch
public int getWrite(SerialPort serial) {
try {
inputStream = serial.getInputStream();
outputStream = serial.getOutputStream();
try {
serial.addEventListener(this);
} catch (TooManyListenersException e) {
System.out.println("Exception in Adding Listener" + e);
serial.notifyOnDataAvailable(true);
} catch (Exception ex) {
System.out.println("Exception in getting InputStream" + ex);
return 0;
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("COM3")) {
try {
serialPort = (SerialPort) portId.open("SimpleWriteApp", 9600);
SimpleWrite wr = new SimpleWrite();
System.out.println(wr.getWrite(serialPort));
} catch (PortInUseException e) {
System.out.println("Port In Use " + e);
try {
outputStream = serialPort.getOutputStream();
return;
} catch (IOException e) {
System.out.println("Error writing to output stream " + e);
try {
serialPort.setSerialPortParams(
9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {
public String arata(String line) {
System.out.println(line);
if (line == null ? "250075C54CD9" == null : line.equals("250075C54CD9")) {
System.out.println(text1);
return "250075C54CD9";
} else if (line == null ? "1D00451A3270" == null : line.equals("1D00451A3270")) {
System.out.println(text2);
return "1D00451A3270";
return line;
this code is working correct getting output at system output terminal but i want use further in as input for my jsp how to get this ?.......
arata method is also working correct in class but it is not returnig value in jsp?
plz give me way how to take string as input ...........
Similar Messages
-
Communicating with Serial Port
Hi,
Hi I have an application that i have to communicate with serial port...
Its working perfectly if am giving all the com settings as constants(pls hav a look @ codea).
But i want to read the port number and baud reate from text file.When i changed the coding,in the serial
setting i was not even able to find the port number and baud rate.it was displaying as buffer size.I think the way i connected the port number and baudrate to the clusture may be wrong(pls refer codeb).How do i fix this problem?
Thanks in Advance....
Solved!
Go to Solution.
Attachments:
modemsetting.JPG 88 KBThe problem I think is that you don't have a cluster tied to the center terminal of the bundler so most of the values don't have a name. Wire the cluster from above to the center terminal on the lower bundler. BTW, it doesn't matter what values are in the cluster you wire up because they will be overwritten.
Mike...
Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion
"... after all, He's not a tame lion..."
Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps -
Any way to communicate with Serial PORT using JavaScript
is there any way to communicate with Serial PORT using JavaScript ??
Dont tell me to do it in java because I need to this on client side not on server side.
such as when client pressed the button, a javascript function will be called and in that function I need to communicate with the serial port of that client... That action will not go to server side.Is there any way to send a string of bytes to the serial port from the client side ?
Just a button on the web page that sends out stuff to the comport.
I was hoping to do this using java script also .. -
Use a HP 34970a with serial port
Hello,
I have labview 7.0 and I have to use a HP 34970a with serial port.
Can anyone say to me any advice to do it?
Where can I find some material?
Thanks
VincentHi Vincent,
> I have labview 7.0 and I have to use a HP 34970a with serial port.
> Can anyone say to me any advice to do it?
> Where can I find some material?
Your first step should be visiting http://ni.com/idnet and search for an
instrument driver for your device (in this case I can promise you will
find one).
The "Learn" link on the same page tells you more about instrument
drivers in general which could be helpfull if this is the first time you
are working with instrument drivers.
Rico -
Problems with serial port synchronization.
Hello to all!
I have an oxygen analyser, the equipment has a serial port for communication, being based the communication on the AK communication protocol.
In order to request to the equipment that responds with the measured value, the following command in hexadecimal is sent: (02 78474B4FE20 03), obtaining like hexadecimal answer the following: (02 58474B4FE203220323038353030 03), in which it is included the measured value.
I need to have the measurement from equipment in a PC, using the AK protocol and the serial port. For this, I have made a (vi) that it writes the read measure command in the serial port, wait a time (150ms) and read the port, this way everything works correctly, but there is a problem and it is that the communication is very slow due to the delay between the writing and the reading.
If I eliminate the delay, the synchronization between the writing and the reading is lost, appearing readings of value 0. I think that is because the PC read the port and the analyser not yet has responded to the request from PC, and this happens in spite of using the options of synchronization of visa read and visa write vi's, (Do I/O synchronously).
I would need to design a (vi) that hoped that the equipment had sent the last data, and then it sends the reading request again, being able this way to make the communication more fast and to eliminate the erroneous readings.
I have attached two examples, first is (vi) that works well, but has the problem of being slow due to the delay, and the second analyzes the received message to know when this complete and then it writes another message of read to analyser, but it appears to me an error (ocurred AT sights read... Time out) after minutes.
I would thank any aid that somebody could offer to me.
Greetings and thanks!
Attachments:
Test_AK.zip 32 KBI don't have a serial port connected on this machine at the moment (they are becoming rare on laptops!) but try this code as a starting place. I notice in your second example you are basing the read on receiving a specific string, in the one I've made you can set the bytes at port compare to a number equivalent in length. I haven't tried it, as I mentioned before, so I appologize for any errors in my code.
P.M.
Putnam
Certified LabVIEW Developer
Senior Test Engineer
Currently using LV 6.1-LabVIEW 2012, RT8.5
LabVIEW Champion
Attachments:
serial read.vi 67 KB -
Is there a Labview Chroma6310 driver that works with serial port instead of GPIB?
The driver that I have downloaded from NI site is based on GPIB, I need to run it via serial port. I don't have GPIB board. I am pretty new in NI world. How easily can I convert the GPIB driver to serial port (ASRL)? Has anybody already done this? Any help on this is highly appreciated.
Best regards,
FarshI haven't looked at the driver and I'm not familiar with the instrument but the conversion should be pretty simple. If it uses VISA for the GPIB communication, the conversion is already done. VISA works with both GPIB and serial - just use the name of the serial port as the VISA reference name. This would be ASRL1 or Com1. If it's an older driver with the traditional GPIB calls, then replace every instance of GPIB Write and GPIB Read with VISA Write and VISA Read. You might also have to add some line terminator like CR/LF to every write. There are a lot of instrument drivers that are compatible with both serial and GPIB. The HP34970 is one that comes to mind. You might want to look at it to see how to do it yourself.
-
Error 37 with serial port / no with hyperterminal
I have added to my Pc a card with two serial port, I can access to them by hyperteminal or by labview but only at port 0 and 1 at the same time or 2 and 3, if not I have an error 37. What can I do?
Error 37 means that LabVIEW cannot find the appropriate serial device. This indicates that one of the following conditions exists:
LabVIEW cannot open the specified serial port;
LabVIEW cannot find the file serpdrv.
Make sure that the serial driver was installed before the board, and that the com ports appear normally in the control panel. If you cannot get it working, contact NI through either phone or email support. Since there are several potential causes, this is difficult to diagnose without more information. You can contact NI using the following webpage.
http://sine.ni.com/apps/we/niae_asc.main
Kim L.
Applications Engineer
National Instruments -
Slow waveform reading time when digitizer is combined with serial port command
Hi All,
I'm using Digitizer PCI-5112 to capture and differenciate waveforms. The waveform measurement from NIScope will be used to determine the command to be sent to Newport ESP 300 motion controller.
When I run read.vi the digitizer will read the waveforms in a high speed as I wanted. For the same waveform, when I combined read.vi with command to ESP 300 (becomes control.vi) the waveform reading becomes very slow (approximately only 1 waveform per second). Is this happened because of hardware limitation of ESP 300 ? Is there anything wrong with my program to send the command to ESP 300? or Is there any other way so I can keep reading the waveform in a high speed? I realize may be this is because I put the waveform reading part and sending command part in the same loop. But I don't know any other way to do this. I would appreciate any clue or answer. Thank you very much.
Attachments:
control.vi 156 KB
read.vi 108 KBHi Dennis, Thank you for the response.
Sorry, I forgot to attach Positioning.vi at my previous message. This Positioning.vi is used to read the position of the axis. I think I get what you mean, I've tried to remove the while loop for the Positioning.vi but it didn't give any effect. Could you kindly check this positioning.vi for me?
Actually this is my first time communicating Labview with motion controller. I got those functions from my colleague. Is there any example or library I can refer for the 'normally used' serial functions? (my connection is RS232) It would be very helpful for me.. Thanx
Attachments:
Positioning.vi 18 KB -
Thinkpad with serial port (RS232)
For my job I need a laptop with a serial (RS232) port.
I have the choice of the following laptops: Lenovo Thinkpad X230, X230T, T430, T530, W530.
Neither of them have a serial port, right?
I saw some mention of an adapter for the ultrabay slim bay, that would support an RS232 adapter.
Does that work for all the above mentioned models?
And if so, would the RS232 port work in the same way as the regular one? I need to program e.g. an Agilent datalogger with Labview to measure and recieve the measured data through the serial port.
Kind regards,
Rachel.thare are two ways :
1. you can buy a usb to seial cable converter.
2. if your laptop have a Docking Station. there is a serial port in the Docking station. Put your laptop on the Docking station, the windows system will automatically recognizes the serial port.
For example, my laptop is thinkpad x61t, Itself does not have any serial port, But there is a serial port on the Docking station.
I am a volunteer, don't work for Lenovo. I am a software engineer.
thinkpad x61t, os:win7 Awavo Software com port monitor serial port monitor -
Communicating Thru COM /Serial port
Hi,
I am developing POS system. The Display pole is connected on com1 and cash drawer on serial port. Can anyone help me how if i have a variable var_amt and want to display it on the pole[com1] what command to use i.e. how to open com / serial port thru forms.
Thanks in AdvanceWe have an old Forms application that needed to dial a modem through the serial port. Here's some code to maybe get you started. I'm going to assume you're on Windows.
Step 1:
Attach an OLE object to your canvas, and point that to MSCOMMLib.MSComm.1 (the MS serial port handler).
Step 2:
Sample code. This is our DIAL_PHONE proedure that receives a phone number, opens the COM port (in our case COM2), sends the modem dial strings, and waits for a respomse back from the mode. I'm not an expert, we just taught ourselves enough to get this one functionality to work.
/* Receives phone string, including area code, and dials a modem on COM2. Disconnects 9 seconds
after dialing (S7=09), assuming the telemarketer will have switched control to their headsets by then
PROCEDURE dial_phone(phone_number IN OUT VARCHAR2) IS
CommHandle ole2.obj_type; -- to hold the interface pointer
hold number;
modem_init VARCHAR2(30) := 'ATQ0V1E1S0=0X4S7=5';
dial_string VARCHAR2(20);
com_err VARCHAR2(100);
outBuf NUMBER;
inchar varchar2(100) := ' ';
loop_count NUMBER(9) := 0;
dial_msg varchar2(100);
time_start binary_integer;
time_end binary_integer;
z NUMBER := 0;
delay NUMBER := 100000;
--Return from check exchange
phone_to_dial VARCHAR2(15);
X VARCHAR2(15);
BEGIN
IF phone_number IS NULL
THEN x := win_alert('OK','No phone number to dial.');
raise form_trigger_failure;
END IF;
logit(:global.debug,'======== Begin DIAL_PHONE (' || phone_number || ') ==============');
-- Check exchange #, If it's in local calling area don't use an area code. Will also
-- add user's long distance data to the number returned, if necessary,
phone_to_dial := check_exchange(phone_number);
CommHandle := forms_ole.get_interface_pointer('b_main_prospect_info.mscomm_ocx');
--Set up the dial string with the passed phone number
dial_string := 'ATDT9' || phone_to_dial;
dial_msg := 'Dialing ' || dial_string || '...';
message(dial_msg,NO_ACKNOWLEDGE);
synchronize;
-- Set the com port to COM2.
OLE2.SET_PROPERTY(CommHandle, 'CommPort', 2);
-- try to close COM2, in case it was open for some reason. 0 = FALSE, -1 = TRUE
begin
OLE2.SET_PROPERTY(CommHandle, 'PortOpen', 0);
exception
when others then null; -- if already open, ignore error
end;
-- Set modem to 1200 baud, no parity, 8 data, and 1 stop bit.
OLE2.SET_PROPERTY(CommHandle, 'Settings', '1200,N,8,1');
-- Open the port. 0 = FALSE, -1 = TRUE
OLE2.SET_PROPERTY(CommHandle, 'PortOpen', -1);
-- find out if the com port has opened successfully. 0 = FALSE, -1 = TRUE
hold := OLE2.GET_num_PROPERTY(CommHandle, 'PortOpen');
IF hold = 0 THEN --the com port could not be opened.
X := WIN_ALERT('OK', 'Your COM2 port (modem) could not be opened. Contact your supervisor');
RAISE form_trigger_failure;
END IF;
-- Send the attention command to the modem. Default setup string
OLE2.SET_PROPERTY(CommHandle, 'Output', modem_init || chr(13));
z := 0;
loop
z := z + 1;
exit when z = delay;
end loop;
-- Run program that give windows control to process info. in output buffer to modem
HOST(:global.gtec_dir || 'DEVENTS.EXE');
--Send the dial string
OLE2.SET_PROPERTY(CommHandle, 'Output', dial_string || chr(13));
z := 0;
loop
z := z + 1;
exit when z = delay;
end loop;
-- Run program that give windows control to process info. in output buffer to modem
HOST(:global.gtec_dir || 'DEVENTS.EXE');
--Clear the dialing string from the input buffer
OLE2.SET_PROPERTY(CommHandle, 'InBufferCount', '0');
* Loop until we get a BUSY or NO CARRIER signal.
loop_count := 0;
time_start := dbms_utility.get_time; -- store loop start in 1/100's of seconds
inchar := ' ';
LOOP
-- Run program that give windows control to process info. in output buffer to modem
HOST(:global.gtec_dir || 'DEVENTS.EXE');
outBuf := OLE2.GET_NUM_PROPERTY(CommHandle, 'InBufferCount');
--Read the response data in the serial port, character by character. Build INCHAR
inchar := inchar || OLE2.GET_CHAR_PROPERTY(CommHandle, 'Input');
--message(inchar);
OLE2.SET_PROPERTY(CommHandle, 'InBufferCount', 0);
* Check to see if a BUSY has been returned
IF INSTR(inchar, 'BUSY') <> 0 THEN
--Close the port
OLE2.SET_PROPERTY(CommHandle, 'PortOpen', 0);
-- Release the MSCOMM handle
OLE2.release_obj(CommHandle);
--Set the list to busy
:b_main_prospect_info.CALL_STATUS_LIST := 'BUSY_NO_ANSWER';
--Process a call marked as Busy/No Answer
process_busy_no_answer;
EXIT;
END IF;
IF INSTR(inchar, 'RING') <> 0 THEN
message(inchar || ' ...', ACKNOWLEDGE);
inchar := ' ';
END IF;
* Check to see if a NO CARRIER has been returned
IF INSTR(inchar, 'NO CARRIER') <> 0 THEN -- happens when they switch to headset. No message shows.
--message('NO DIAL TONE' || ' ...', ACKNOWLEDGE);
inchar := ' ';
GO_ITEM('CALL_STATUS_LIST');
EXIT;
END IF;
*Check to see if a OK has been returned
IF INSTR(inchar, 'OK') <> 0 THEN
message(inchar || ' ...', ACKNOWLEDGE);
inchar := ' ';
GO_ITEM('CALL_STATUS_LIST');
EXIT;
END IF;
loop_count := loop_count + 1;
IF MOD(loop_count,1000) = 0
THEN dial_msg := dial_msg || '.';
message(dial_msg,NO_ACKNOWLEDGE);
synchronize;
END IF;
time_end := dbms_utility.get_time;
-- Compare current time to loop start time in 1/100's of seconds. If more than 10 seconds, end.
if time_end - time_start > 1500
THEN message('Problem dialing number. Result response not received from modem.', ACKNOWLEDGE);
message(' ');
GO_ITEM('CALL_STATUS_LIST');
EXIT;
END IF;
END LOOP;
OLE2.SET_PROPERTY(CommHandle, 'Output', 'ATH' || chr(13));
z := 0;
loop
z := z + 1;
exit when z = delay/10;
end loop;
--Close the port
OLE2.SET_PROPERTY(CommHandle, 'PortOpen', 0);
OLE2.release_obj(CommHandle);
--Give list box focus
update tele.gtec_login_tbl
set last_dialed = phone_number,
last_dialed_time = sysdate
where v_user_id = user;
forms_ddl('commit');
if to_number(:global.address_id) > 0
then GO_ITEM('b_main_prospect_info.call_status_list');
else GO_ITEM('b_manual_call.v_call_outcome');
end if;
EXCEPTION
when others then
logit(:global.debug,'Error dialing phone');
--Give list box focus
if to_number(:global.address_id) > 0
then GO_ITEM('b_main_prospect_info.call_status_list');
else GO_ITEM('b_manual_call.v_call_outcome');
end if;
END; -
Iam trying to send a message from my PC to a simulator through serial ports.Does anyone help me how can i proceed?
check out the javax.comm package and documentation, it has some sample programs for sending and recieving on the serial ports. Be careful with the installation, there have been some threads about this lately, but some of the files need to be installed in c:\program files\jre or similar, you can search the forum. Hope this helps :)
-
are there any laptops by hp that have a serial port along with usb?? I really need a true serial port.
Hi 241R ,
Here is a link to probook 6470b which has a serial port -http://www8.hp.com/h20195/v2/getpdf.aspx/c04296097.pdf?ver=4
Hope it helps
Regards,
PraTH_KR
Although I am an HP employee, I am speaking for myself and not for HP.
**Click on “Kudos” Star if you think this reply helped** Or Mark it as "Solved" if issue got fixed. -
Fastest Thinkpad with serial port
Hello!
what is the fastest thinkpad with dock station or port replication that still have the serial port that has been produced?
Is it the X60 ?
I have my faithful T30 but it is a little slow now...
CiaoWelcome to the forum!
Although the integrated serial port died with T30 and A31p, it's still available on dock for most newer ThinkPads:
http://www-307.ibm.com/pc/support/site.wss/MIGR-61297.html
Good luck.
Cheers,
George
In daily use: R60F, R500F, T61, T410
Collecting dust: T60
Enjoying retirement: A31p, T42p,
Non-ThinkPads: Panasonic CF-31 & CF-52, HP 8760W
Starting Thursday, 08/14/2014 I'll be away from the forums until further notice. Please do NOT send private messages since I won't be able to read them. Thank you. -
Looking for 17 inch tecra with serial port
do they exist?
any current models with rs-232 serial port still on board?
i know the 14 inch models have it, but i need a 17 inch model..
grtPretty sure there are no 17" Tecra models.
-
Pc to h/w communication by using serial port
I have write a serial port codding but thre is problem in accessing the javax.comm.*' packege.
I had downloaded that package on my pc but its not working.
Could anybody help me?Hmm. Urgent. When is your project due? What have you tried so far? Whats not working? First you need to verify that all your hardware is connected properly and the UART is properly configured on teh 8051. Then you need to make sure that the software on both the PC and the 8051 are both working properly. Just curious, what class is this project for?
Maybe you are looking for
-
Web printing crystal report hangs on report.PrintOptions.PrinterName
Hello, I have a report web page that displays a crystal report. I have added a modal popup to allow them to select their printers. When I go to print the report is hangs on the line of rpt.PrintOptions.PrinterName = li.Text. The printer names are
-
My iPhoto is no longer executable?
Hello, Recently Ive purchased the mac app "Iboostup" and used the app shrinkinking function. I followed the steps the app gave me which was "replace the shruken apps with the old ones". In which case I did and all the programs worked except for Iphot
-
I synced my iPhone 4 yesterday. Now, most of my notes are gone. How can I get them back?
-
Importing Pictures and Tags from Photoshop Album 2.0 to IPhoto
I will be getting a new imac in a few days and was wondering if anyone knows if there is a way I can import all my photos from Photoshop Album 2.0 to iphoto'08 without losing the tags I already created for each photo (pulling the tags in and having t
-
How to select multiple clips???
I am a very avid iMovie user and now this new version has me so confused. I have the basics down, but I can't figure out how to select all clips and dump them into the "timeline" area. I can select them one at a time and place them in the assembly ar