This code is meant to take an input from the serial port and then save the input from the serial port as the name and as the data to a text file but all i am getting is an empty text file or a text file with only "," in it. It would be much appreciated if anyone could help with this problem. Thanks - Private Sub Form_Unload(Cancel As Integer)
-
MSComm1.PortOpen = False ' Close the comm port
-
End Sub
-
-
Private Sub Timer1_Timer()
-
If MSComm1.PortOpen = False Then ' If comm port is not open
-
MSComm1.PortOpen = True ' Open it
-
End If
-
-
If MSComm1.InBufferCount > 0 Then ' If theres data in comm buffer
-
inst = inst + MSComm1.Input ' Get the data
-
Text1.Text = inst ' Show its value
-
Filename.Text = Text1.Text
-
Text2.Text = Text1.Text
-
End If
-
If Text1.DataChanged < True Then
-
Open "C:\test\" + Filename.Text + ".txt" For Output As #1 'location of the file.
-
Write #1, Text1.Text, Text2.Text 'The things you want to save
-
Close 1
-
End If
-
-
End Sub
8 12179
Sorry didn't add this to first post but anyway new to this type of thing.
I was working on making it save to a specific folder in many small files for me to sort through the data (small amounts of information currently for it) without a save popup or dialog to save. The timer is also set to 1000mils didn't know if that had any bearing on the saves or not. Thanks again for any input anyone can offer.
Two very important questions... - What version of VB is this? (From the looks of it, I'd guess VB6)
- Are you getting the wrong data, or just writing the files incorrectly?
If you don't know the answer to the second question, then you need to investigate and work it out. After all, there are two distinct operations going on - you need to know which one is misbehaving before you can fix it.
This code is meant to take an input from the serial port and then save the input from the serial port as the name and as the data to a text file but all i am getting is an empty text file or a text file with only "," in it. It would be much appreciated if anyone could help with this problem. Thanks - Private Sub Form_Unload(Cancel As Integer)
-
MSComm1.PortOpen = False ' Close the comm port
-
End Sub
-
-
Private Sub Timer1_Timer()
-
If MSComm1.PortOpen = False Then ' If comm port is not open
-
MSComm1.PortOpen = True ' Open it
-
End If
-
-
If MSComm1.InBufferCount > 0 Then ' If theres data in comm buffer
-
inst = inst + MSComm1.Input ' Get the data
-
Text1.Text = inst ' Show its value
-
Filename.Text = Text1.Text
-
Text2.Text = Text1.Text
-
End If
-
If Text1.DataChanged < True Then
-
Open "C:\test\" + Filename.Text + ".txt" For Output As #1 'location of the file.
-
Write #1, Text1.Text, Text2.Text 'The things you want to save
-
Close 1
-
End If
-
-
End Sub
what's the interval of ur timmer?
try to increase it or u may use onComm event insted of timmer..
cut and paste the code of text1.datachanged into inbuffercount>0
try it
Good Luck
Two very important questions...- What version of VB is this? (From the looks of it, I'd guess VB6)
- Are you getting the wrong data, or just writing the files incorrectly?
Yeah the VB version is 6 and its not wrong data really just when it does get information on that port it does save a text file only its names ".txt" and it only contains "" or "," at most and does not contain any of the data
what's the interval of ur timmer?
try to increase it or u may use onComm event insted of timmer..
cut and paste the code of text1.datachanged into inbuffercount>0
try it
Good Luck
Thanks vijaydiwakari will try what you said. Also tried moving the code fo text1.datachanged up under inbuffercount but it gave me that same response. Keep those replies comming any informations that leads me towards a semi working program is better than what i got so far :)
Yeah the VB version is 6 and its not wrong data really just when it does get information on that port it does save a text file only its names ".txt" and it only contains "" or "," at most and does not contain any of the data
Sounds as though vijaydiwakar is probably on the right track. You're probably checking the port too often, before any data arrives, or something. The OnComm event does sound like a better option.
Let us know how it goes.
Also, consider simply writing stuff to the immediate window rather than actually creating the files. It's much quicker and simpler to debug that way.
Thanks for the help so far i have this and it works...now lemme add some stuff and see what i can screw up next *grins* - Private Sub Command1_Click()
-
Open "z:\" + Test1 + ".txt" For Append As #1
-
Write #1, Text1
-
Close #1
-
End Sub
-
Private Sub Form_Load()
-
If MSComm1.PortOpen = False Then ' If comm port is not open
-
MSComm1.PortOpen = True ' Open it
-
End If
-
End Sub
-
Private Sub MSComm1_OnComm()
-
If MSComm1.InBufferCount > 0 Then
-
inst = MSComm1.Input
-
Text1 = inst
-
-
End If
-
End Sub
-
Private Sub Text1_Change()
-
Call Command1_Click
-
End Sub
Thanks for the help so far i have this and it works...now lemme add some stuff and see what i can screw up next *grins*
That's the spirit! :D
Let us know how it goes. And vijaydiwakar, thanks for your help.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: ^CeFoS^ |
last post by:
Hello to everybody,
I've done an application that draws in a frame the trajectory of a
robot. The robot position is readed through the serial port, and
several commands are wrote through the...
|
by: Chris |
last post by:
Here's the situation:
I work at a scientific institution and I have a portable electronic
device which is used to take measurements. The device produces a very
small amount of numerical data,...
|
by: bloggsfred00 |
last post by:
I need to read incoming bytes on a COM port but I do not want to have
the script hang if there is nothing to read.
Is there any way to have PHP interrogate a COM port buffer to see if
there is...
|
by: pranavkrish |
last post by:
I am using serialPort control to read data from a barcode scanner , Can you please suggest me the most reliable methof to do this. Now I generate an even based on the data received in the serial port...
|
by: John Wright |
last post by:
I am trying to read the data from a device on a serial port. I connect just
fine and can receive data fine in text mode but not in binary mode.
In text mode the data from the device comes in...
|
by: crampio |
last post by:
Hello everyone,
I generally look at Google and other websites before I post a question, but trust me I still cannot find and answer to this problem.
I'm using VB.net. My problem being is that I...
|
by: Hal Vaughan |
last post by:
I've done a fair amount of Googling for information on reading the serial
port in C++ (and in Linux). Unfortunately, out of every 4 hits, 1 seems to
be an unanswered question, 1 is someone saying,...
|
by: ghjk |
last post by:
I'm trying to read sms from GSM modem using c#. my code is only working for at command. When I enter at+cmgr=1 it says"ERROR". but when i typr it hyperterminal. It is working.Could you please tell me...
|
by: =?Utf-8?B?Q2hhcmxpZQ==?= |
last post by:
Hi,
This apparently is a common problem and I've yet to read a solution that
actually works for my specific situation.
I have a Zebra RW220 printer that I connect to via Bluetooth connection...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |