reading the serial port.
-
- Posts: 24
- Joined: Sep 08, 2010 20:27
- Location: Florida
reading the serial port.
In Qb when using the serial port I would do a line like this
ON COM(1)
then do a com handler subroutine to get the data.
FB does not really have this, any ideas?
I am new to FB, but have alot of equipment running using com ports using the method I described talking to Transducers and motors and such.
ON COM(1)
then do a com handler subroutine to get the data.
FB does not really have this, any ideas?
I am new to FB, but have alot of equipment running using com ports using the method I described talking to Transducers and motors and such.
-
- Posts: 24
- Joined: Sep 08, 2010 20:27
- Location: Florida
reading the serial port.
Thank you for the reply.
Now to show my heavy DOS , 68HC11 background, I will need to go research "Threads"
I knew eventually I would have to leave my well known (comfortable)routines.
Now to show my heavy DOS , 68HC11 background, I will need to go research "Threads"
I knew eventually I would have to leave my well known (comfortable)routines.
Here is an example of a routine I use in one of my programs to get the temperature reading from a Fluke temperature meter. You should be able to adapt this to your needs.
Code: Select all
Dim Shared quit As Integer
Dim Shared meterval As String
Dim thread As Any Ptr
'temperature meter reading thread
Sub mythread(param As Any Pointer)
While quit=0
While Loc(5)=0
If quit<>0 Then
Exit Sub
End If
Sleep 10,0
Wend
Input #5,meterval
Wend
End Sub
Open com "com1:9600,n,8,1,cs0,ds0,cd0" As #5
Sleep 200
If Err <> 0 Then
Cls
Print "Error opening temp meter port "
Sleep
End
End If
Sleep 800
Print #5,"T"' start meter
thread=Threadcreate(@mythread,0) ' create thread for temp meter
Do
Print meterval
Sleep 10,0
Loop Until Multikey(1)
quit = 1
Threadwait(thread)
-
- Posts: 24
- Joined: Sep 08, 2010 20:27
- Location: Florida
reading a serial port
Thanks again. I copied your code and I will try it here in a little bit. After looking at it I think I have a better understanding. Thanks again.
I will post the result, Good or bad.
I will post the result, Good or bad.
-
- Posts: 24
- Joined: Sep 08, 2010 20:27
- Location: Florida
reading the serial port.
AWESOME.
The code worked right out of the box. All I did was substitute 9600 with 38400.
The code worked right out of the box. All I did was substitute 9600 with 38400.
Great! Here is an example that will only display if the value is updated.
Code: Select all
Dim Shared quit As Integer
Dim Shared meterval As String
Dim thread As Any Ptr
'temperature meter reading thread
Sub mythread(param As Any Pointer)
While quit=0
While Loc(5)=0
If quit<>0 Then
Exit Sub
End If
Sleep 10,0
Wend
Input #5,meterval
Wend
End Sub
Open com "com1:9600,n,8,1,cs0,ds0,cd0" As #5
Sleep 200
If Err <> 0 Then
Cls
Print "Error opening temp meter port "
Sleep
End
End If
Sleep 800
Print #5,"T"' start meter
thread=Threadcreate(@mythread,0) ' create thread for temp meter
meterval = "invalid"
Do
If meterval <> "invalid" Then
Print meterval
meterval = "invalid"
End If
Sleep 10,0
Loop Until Multikey(1)
quit = 1
Threadwait(thread)
-
- Posts: 24
- Joined: Sep 08, 2010 20:27
- Location: Florida
reading the serial port.
The device I am reading is constantly transmitting. All I really need to do now is decode the information and perform some math to get my final usable information. By the way the second program also worked right out of the box!
Thanks again. When I get this part all the way done I will post the result. Hopefully today.
Thanks again. When I get this part all the way done I will post the result. Hopefully today.
-
- Posts: 24
- Joined: Sep 08, 2010 20:27
- Location: Florida
reading the serial port
Ok. I am full up and running. The calculations are complete. In this respect FB is like QB. I had to DIM some of the variables , but other than that I am displaying Altitude at a very fast rate,.
Next job is a nice looking screen. Most of my programs use screen 13 for the big fonts, I may do some oage flipping , because FB seems to be very fast.
One more thing that I will need to do is see how the final EXE reacts to some of the platforms I am using.
Thanks again
Next job is a nice looking screen. Most of my programs use screen 13 for the big fonts, I may do some oage flipping , because FB seems to be very fast.
One more thing that I will need to do is see how the final EXE reacts to some of the platforms I am using.
Thanks again
Hello there people.
phishguy, could you explain a little bite each part of the code that you have written? I was thinking to do a project like your, but, instead of being a temperature equipment, I was thinking to do that on a Fluke 45.
And more, I thought doing some kind of data logger or something, GUI format.
Best regards,
Charles
phishguy, could you explain a little bite each part of the code that you have written? I was thinking to do a project like your, but, instead of being a temperature equipment, I was thinking to do that on a Fluke 45.
And more, I thought doing some kind of data logger or something, GUI format.
Best regards,
Charles
-
- Posts: 35
- Joined: Nov 14, 2019 17:04
Re: reading the serial port.
I want to connect the MCP3201 directly to the LPT
to get the code from the ADC requires 50 requests to the port.
one request( for both writing and reading )using this library takes 3+ μS.
I remember exactly that when it was under Windows xp
through the built-in access to ports, the request was 1.2 μS.
How can I reduce the request time ?
here is the working code STM32
to get the code from the ADC requires 50 requests to the port.
one request( for both writing and reading )using this library takes 3+ μS.
I remember exactly that when it was under Windows xp
through the built-in access to ports, the request was 1.2 μS.
How can I reduce the request time ?
here is the working code STM32
Code: Select all
unsigned short Read_MCP3201 (void)
{
int i=0;
unsigned short AdcResult=0; //must 16 BIT
CS_MCP3201_High; ///CS
__disable_irq ();
for(i=0;i<16;i++)
{
CLK_MCP3201_Low; //ADC_CLK=0
CLK_MCP3201_High; ///clk
AdcResult<<=1;
if(HAL_GPIO_ReadPin(DATA_MCP3201_GPIO_Port, DATA_MCP3201_Pin))
{ AdcResult |= 1;}
}
__enable_irq ();
CS_MCP3201_High; ///CS
AdcResult<<=3;
AdcResult>>=4;
return(AdcResult);
}
-
- Posts: 35
- Joined: Nov 14, 2019 17:04
Re: reading the serial port.
SORY // DOUBLE