Access to RS232 ports with fpc

classic Classic list List threaded Threaded
29 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Access to RS232 ports with fpc

Holger Bruns
Hello,

I am new to this list. For programming the serial ports on a linux
system, I tried to use the "serial" unit. i don't understand the
declaration for "buffer" in the function below, because no type is
declared for "buffer". How can I read a character from the selected
serial port? This is the part of the serial unit I am talking about:

  function SerRead(Handle: TSerialHandle; var Buffer; Count: LongInt):
LongInt;
    begin
    Result := fpRead(Handle, Buffer, Count);
  end;

I hope so far, you can help me out with an advice.

Best regards, Holger

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Access to RS232 ports with fpc

Jürgen Hestermann
> function SerRead(Handle: TSerialHandle; var Buffer; Count: LongInt): LongInt;
>    begin
>    Result := fpRead(Handle, Buffer, Count);
>    end;
> i don't understand the
> declaration for "buffer" in the function below, because no type is
> declared for "buffer".

I believe that the type is irrelevant, you can use whatever you want. I
think that it's just used by fpRead to buffer data. You only provide the
space for the buffer but you don't need to read it directly. It seems
that Count has to be the size of the buffer. But I am just guessing....

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Access to RS232 ports with fpc

Holger Bruns
Jürgen Hestermann schrieb:

>> function SerRead(Handle: TSerialHandle; var Buffer; Count: LongInt):
>> LongInt;
>>    begin
>>    Result := fpRead(Handle, Buffer, Count);
>>    end;
>> i don't understand the declaration for "buffer" in the function
>> below, because no type is declared for "buffer".
>
> I believe that the type is irrelevant, you can use whatever you want.
> I think that it's just used by fpRead to buffer data. You only provide
> the space for the buffer but you don't need to read it directly. It
> seems that Count has to be the size of the buffer. But I am just
> guessing....
My hope was to read more than guessing. As I pointed out, the "buffer"
seems not to be filled with incoming data from the selected serial port.
Hence I cannot read just this data, and serread seems to be faulty. For
this reason I ask for an advice. I need to look on working sample code
to use this function in a working manner. In my example, serread replies
only, what has been written with serwrite right before. Not even
serflush, executed right after serwrite, can solve this problem to me.

Holger

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Access to RS232 ports with fpc

Martin Frb
Holger Bruns wrote:

> Jürgen Hestermann schrieb:
>>> function SerRead(Handle: TSerialHandle; var Buffer; Count: LongInt):
>>> LongInt;
>>>    begin
>>>    Result := fpRead(Handle, Buffer, Count);
>>>    end;
>>> i don't understand the declaration for "buffer" in the function
>>> below, because no type is declared for "buffer".
>>
>> I believe that the type is irrelevant, you can use whatever you want.
>> I think that it's just used by fpRead to buffer data. You only
>> provide the space for the buffer but you don't need to read it
>> directly. It seems that Count has to be the size of the buffer. But I
>> am just guessing....
> My hope was to read more than guessing. As I pointed out, the "buffer"
> seems not to be filled with incoming data from the selected serial
> port. Hence I cannot read just this data, and serread seems to be
> faulty. For this reason I ask for an advice. I need to look on working
> sample code to use this function in a working manner. In my example,
> serread replies only, what has been written with serwrite right
> before. Not even serflush, executed right after serwrite, can solve
> this problem to me.

var foo;
const foo;

are hidden pointer types.
That is foo would contain a pointer, but you never see this. You never
have to get the address of something, and you never have to dereference it.

As for using this:

SerRead(Handle, Buffer, 0)

Buffer must be the first byte of a block of memory

you can do:
var buffer: Array of byte;

SetLength(Buffer, 1000);
SerRead(Handle, Buffer[0], 1000);

NOTE the [0] index you supply the first byte of your buffer.
FPC is internally taking the address of this first bytes, and then 1000
bytes from this address on will be used

----
Example 2

var buffer: ^Byte; // bointer to byte

Buffer = GetMem.....; // buffer contains the address of your memory
SerRead(Handle, Buffer^, 1000); // again ^ dereference it

----
Example 3
There are case where the [0] or ^ is optional, but you need to
understand a lot how fpc allocates memory

var buffer: Array [0..999] of byte;

SerRead(Handle, Buffer, 1000); // you can do buffer[0] too

-------

The most common fault is, that people forget to specify [0] or ^ and
that leads to errors.

The below is WRONG:
var buffer: ^Byte; // bointer to byte

Buffer = GetMem.....; // buffer contains the address of your memory
SerRead(Handle, Buffer, 1000); // missing ^

It is wrong because buffer itself is a variable having 4 or 8 byte (32
or 64 bit platform). Buffer only contains the address of where the data is.
If you pass buffer like in the example above, "SerRead" willbut the
rsult into the 4 bytes of the variable itself (and then writing to
random memory behind this)


Martin







_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Access to RS232 ports with fpc

Felipe Monteiro de Carvalho
It may be useful to know that there is a serial communication example
using Synaser here:

http://wiki.lazarus.freepascal.org/Hardware_Access#Serial_Communication

It's much easier to use then using the lower level routines yourself.

--
Felipe Monteiro de Carvalho
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Access to RS232 ports with fpc

Holger Bruns
In reply to this post by Martin Frb
Martin schrieb:

> Holger Bruns wrote:
>> Jürgen Hestermann schrieb:
>>>> function SerRead(Handle: TSerialHandle; var Buffer; Count:
>>>> LongInt): LongInt;
>>>>    begin
>>>>    Result := fpRead(Handle, Buffer, Count);
>>>>    end;
>>>> i don't understand the declaration for "buffer" in the function
>>>> below, because no type is declared for "buffer".
>>>
>>> I believe that the type is irrelevant, you can use whatever you
>>> want. I think that it's just used by fpRead to buffer data. You only
>>> provide the space for the buffer but you don't need to read it
>>> directly. It seems that Count has to be the size of the buffer. But
>>> I am just guessing....
>> My hope was to read more than guessing. As I pointed out, the
>> "buffer" seems not to be filled with incoming data from the selected
>> serial port. Hence I cannot read just this data, and serread seems to
>> be faulty. For this reason I ask for an advice. I need to look on
>> working sample code to use this function in a working manner. In my
>> example, serread replies only, what has been written with serwrite
>> right before. Not even serflush, executed right after serwrite, can
>> solve this problem to me.
>
> var foo;
> const foo;
>
> are hidden pointer types.
> That is foo would contain a pointer, but you never see this. You never
> have to get the address of something, and you never have to
> dereference it.
>
> As for using this:
>
> SerRead(Handle, Buffer, 0)
>
> Buffer must be the first byte of a block of memory
>
> you can do:
> var buffer: Array of byte;
>
> SetLength(Buffer, 1000);
> SerRead(Handle, Buffer[0], 1000);
>

Hi Martin,

I checked this out. It works not reliable. Sometimes I get real data,
sometimes the data are corrupted. I have no idea to rule out corrupted
data. I also tried to use the synaser unit, which can be found on the
internet. The demo code "sertest" crashes instantly.

The only way to get rid of this problem is a direct port access. But
direct port access is only possible for the first 200 port addresses. A
"port" array is not yet implemented, and the required higher port
addresses are strictly ruled out from every use through compiled fpc
programs. I do not understand this harsh policy. And I have no idea to
rule this policy out. If there is any possibility to get access to all
ports on the system without access error messages, please let me know.
If I need to alter the compiler, is there a patch available? Or should I
use gcc rather than fpc to match my ideas?

The real sad thing is, that one cannot produce software for Linux, based
on the restricted free pascal compiler. I am really disappointed.

Best regards, Holger

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Access to RS232 ports with fpc

Marco van de Voort
In our previous episode, Holger Bruns said:

>
> The only way to get rid of this problem is a direct port access. But
> direct port access is only possible for the first 200 port addresses. A
> "port" array is not yet implemented, and the required higher port
> addresses are strictly ruled out from every use through compiled fpc
> programs. I do not understand this harsh policy. And I have no idea to
> rule this policy out. If there is any possibility to get access to all
> ports on the system without access error messages, please let me know.
> If I need to alter the compiler, is there a patch available? Or should I
> use gcc rather than fpc to match my ideas?
>
> The real sad thing is, that one cannot produce software for Linux, based
> on the restricted free pascal compiler. I am really disappointed.

WHere is this limitation? I'm not aware that FPC has a limitation that GCC
hasn't. More probably it is an OS limitation, or do you need to ask
permission for higher portnumbers with ioperm.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Access to RS232 ports with fpc

Roberto Padovani
In reply to this post by Holger Bruns
There's nothing limited within the compiler! If you have the same
knowledge and expertise of Pascal and C,  IMHO with gcc you will only
be complicating your life.

About serial port, low level routine need some practice, but you can
go quickly to the point with this component for lazarus:

http://sourceforge.net/projects/cportlaz/

You get threaded data reception and even packet parsing with automatic
event fire on a specific packet pattern.
I am using it to develop hardware monitors which are running smoothly
also on old fashioned hardware, so there's no packet loss or packet
corruption.

R#


2009/11/2 Holger Bruns <[hidden email]>:

> Martin schrieb:
>>
>> Holger Bruns wrote:
>>>
>>> Jürgen Hestermann schrieb:
>>>>>
>>>>> function SerRead(Handle: TSerialHandle; var Buffer; Count: LongInt):
>>>>> LongInt;
>>>>>   begin
>>>>>   Result := fpRead(Handle, Buffer, Count);
>>>>>   end;
>>>>> i don't understand the declaration for "buffer" in the function below,
>>>>> because no type is declared for "buffer".
>>>>
>>>> I believe that the type is irrelevant, you can use whatever you want. I
>>>> think that it's just used by fpRead to buffer data. You only provide the
>>>> space for the buffer but you don't need to read it directly. It seems that
>>>> Count has to be the size of the buffer. But I am just guessing....
>>>
>>> My hope was to read more than guessing. As I pointed out, the "buffer"
>>> seems not to be filled with incoming data from the selected serial port.
>>> Hence I cannot read just this data, and serread seems to be faulty. For this
>>> reason I ask for an advice. I need to look on working sample code to use
>>> this function in a working manner. In my example, serread replies only, what
>>> has been written with serwrite right before. Not even serflush, executed
>>> right after serwrite, can solve this problem to me.
>>
>> var foo;
>> const foo;
>>
>> are hidden pointer types.
>> That is foo would contain a pointer, but you never see this. You never
>> have to get the address of something, and you never have to dereference it.
>>
>> As for using this:
>>
>> SerRead(Handle, Buffer, 0)
>>
>> Buffer must be the first byte of a block of memory
>>
>> you can do:
>> var buffer: Array of byte;
>>
>> SetLength(Buffer, 1000);
>> SerRead(Handle, Buffer[0], 1000);
>>
>
> Hi Martin,
>
> I checked this out. It works not reliable. Sometimes I get real data,
> sometimes the data are corrupted. I have no idea to rule out corrupted data.
> I also tried to use the synaser unit, which can be found on the internet.
> The demo code "sertest" crashes instantly.
>
> The only way to get rid of this problem is a direct port access. But direct
> port access is only possible for the first 200 port addresses. A "port"
> array is not yet implemented, and the required higher port addresses are
> strictly ruled out from every use through compiled fpc programs. I do not
> understand this harsh policy. And I have no idea to rule this policy out. If
> there is any possibility to get access to all ports on the system without
> access error messages, please let me know. If I need to alter the compiler,
> is there a patch available? Or should I use gcc rather than fpc to match my
> ideas?
>
> The real sad thing is, that one cannot produce software for Linux, based on
> the restricted free pascal compiler. I am really disappointed.
>
> Best regards, Holger
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Access to RS232 ports with fpc

Jonas Maebe-2
In reply to this post by Holger Bruns
Holger Bruns wrote on Mon, 02 Nov 2009:

> Martin schrieb:
>> you can do:
>> var buffer: Array of byte;
>>
>> SetLength(Buffer, 1000);
>> SerRead(Handle, Buffer[0], 1000);
>
> I checked this out. It works not reliable. Sometimes I get real  
> data, sometimes the data are corrupted. I have no idea to rule out  
> corrupted data.

You have to check the result of the serread routine. Since it returns  
the result of the fpread call, "man 2 read" will tell you what those  
results mean. In short,
a) result >= 0: actual number of bytes read (the 1000 you pass is just  
a maximum)
b) result < 0: an error occurred


Jonas

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Access to RS232 ports with fpc

Frank Peelo
In reply to this post by Holger Bruns
Jürgen Hestermann schrieb:

> function SerRead(Handle: TSerialHandle; var Buffer; Count: LongInt):
> LongInt;
>    begin
>    Result := fpRead(Handle, Buffer, Count);
>    end;
> i don't understand the declaration for "buffer" in the function
> below, because no type is declared for "buffer".

Untyped parameters date back to early TurboPascal.

http://www.freepascal.org/docs-html/ref/refsu48.html

     Variable and constant parameters can be untyped. In that case the
     variable has no type, and hence is incompatible with all other
     types. However, the address operator can be used on it, or it can be
     can passed to a function that has also an untyped parameter. If an
     untyped parameter is used in an assigment, or a value must be
     assigned to it, a typecast must be used.

This can be used when you create a variable to use as a block of memory,
for a buffer. The size of the buffer has to be known to the function, so
it would typically be passed in as a parameter.

I'd guess the reason for adding these to the language is that the caller
has to have a variable to pass, so you are less likely to pass an
invalid pointer, i.e. one which has not been set to point at allocated
memory.

FP

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Access to RS232 ports with fpc

Holger Bruns
In reply to this post by Jonas Maebe-2
Jonas Maebe schrieb:

> Holger Bruns wrote on Mon, 02 Nov 2009:
>
>> Martin schrieb:
>>> you can do:
>>> var buffer: Array of byte;
>>>
>>> SetLength(Buffer, 1000);
>>> SerRead(Handle, Buffer[0], 1000);
>>
>> I checked this out. It works not reliable. Sometimes I get real data,
>> sometimes the data are corrupted. I have no idea to rule out
>> corrupted data.
>
> You have to check the result of the serread routine. Since it returns
> the result of the fpread call, "man 2 read" will tell you what those
> results mean. In short,
> a) result >= 0: actual number of bytes read (the 1000 you pass is just
> a maximum)
> b) result < 0: an error occurred

Thank you. I checked this out, but every incoming character is
interpreted as zero, regardless of its real value.

Holger

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Access to RS232 ports with fpc

Holger Bruns
In reply to this post by Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho schrieb:
> It may be useful to know that there is a serial communication example
> using Synaser here:
>
> http://wiki.lazarus.freepascal.org/Hardware_Access#Serial_Communication
>  
Yes, thank you. I checked this out. The procedure reccvbyte, as used in
this manner:

 Write(IntToHex(ser.RecvByte(1000), 2), ' ');

reads every incoming character as zero. Simply, is does not work.
> It's much easier to use then using the lower level routines yourself.
>
>  
I try to implement a direct port access. If this also leads to access
errors, I should give it up. Embarassing.

Holger



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Access to RS232 ports with fpc

Jonas Maebe-2
Holger Bruns wrote on Mon, 02 Nov 2009:

> Felipe Monteiro de Carvalho schrieb:
>> It may be useful to know that there is a serial communication example
>> using Synaser here:
>>
>> http://wiki.lazarus.freepascal.org/Hardware_Access#Serial_Communication
>>
> Yes, thank you. I checked this out. The procedure reccvbyte, as used  
> in this manner:
>
> Write(IntToHex(ser.RecvByte(1000), 2), ' ');
>
> reads every incoming character as zero. Simply, is does not work.

Are you certain that your serial port is actually configured  
correctly? Many people have successfully used these units in the past,  
so it most likely seems like a configuration or usage problem.

Moreover, the serread function you posted earlier is about as low  
level as you can get: it directly reads bytes from a handle using a  
system call. If that never works, then the problem is almost certainly  
completely unrelated to anything FPC.

You may also want to post the complete test program that you are  
using, maybe there is an error somewhere.

> I try to implement a direct port access. If this also leads to  
> access errors, I should give it up. Embarassing.

Please stop complaining in virtually every reply to people trying to help you.


Jonas

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Access to RS232 ports with fpc

Holger Bruns
In reply to this post by Holger Bruns
Holger Bruns schrieb:
> I try to implement a direct port access. If this also leads to access
> errors, I should give it up. Embarassing.
Accessing ports is limited to ports < 03ffh, more ports cannot be
released with fpioperm. This means to me, successful serial port access
on higher addresses cannot yet be implemented with fpc. If this policy
can be ruled out, let me know.

Holger

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Access to RS232 ports with fpc

Florian Klämpfl
Holger Bruns schrieb:
> Holger Bruns schrieb:
>> I try to implement a direct port access. If this also leads to access
>> errors, I should give it up. Embarassing.
> Accessing ports is limited to ports < 03ffh, more ports cannot be
> released with fpioperm. This means to me, successful serial port access
> on higher addresses cannot yet be implemented with fpc. If this policy
> can be ruled out, let me know.

This has nothing to do with fpc. Maybe you should read the ioperm man
page and you might start to understand things.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Access to RS232 ports with fpc

Jonas Maebe-2
In reply to this post by Holger Bruns
Holger Bruns wrote on Mon, 02 Nov 2009:

> Accessing ports is limited to ports < 03ffh, more ports cannot be  
> released with fpioperm. This means to me, successful serial port  
> access on higher addresses cannot yet be implemented with fpc. If  
> this policy can be ruled out, let me know.

fpioperm directly passes whatever parameters you give it to the Linux  
kernel. If the kernel refuses you access to those ports, there is  
nothing FPC can do about that.


Jonas

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Access to RS232 ports with fpc

Holger Bruns
In reply to this post by Florian Klämpfl
Florian Klaempfl schrieb:

> Holger Bruns schrieb:
>  
>> Holger Bruns schrieb:
>>    
>>> I try to implement a direct port access. If this also leads to access
>>> errors, I should give it up. Embarassing.
>>>      
>> Accessing ports is limited to ports < 03ffh, more ports cannot be
>> released with fpioperm. This means to me, successful serial port access
>> on higher addresses cannot yet be implemented with fpc. If this policy
>> can be ruled out, let me know.
>>    
>
> This has nothing to do with fpc. Maybe you should read the ioperm man
> page and you might start to understand things.
>  

I am new to linux and wrote only small things for MS-DOS before. As far
as I could read on the internet, fpc uses ioperm and iopl, and I will
try to use iopl to get access to the ports I want to use. The problem is
indeed the rights management, as far as I can read on several web pages,
which addresses my technical problem. The rights management cannot be
ruled out by an application like I intend to write. But I can deal with
it, I hope so far.

My posts to this list are not written against any person. My problem is
not an interpersonal problem, but a technical question, and I try to
find a good answer to it.

Holger

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Access to RS232 ports with fpc

Bernd Mueller-3
In reply to this post by Holger Bruns
Holger Bruns wrote:
> Holger Bruns schrieb:
>> I try to implement a direct port access. If this also leads to access
>> errors, I should give it up. Embarassing.
> Accessing ports is limited to ports < 03ffh, more ports cannot be
> released with fpioperm. This means to me, successful serial port access
> on higher addresses cannot yet be implemented with fpc. If this policy
> can be ruled out, let me know.

so you must use a very special serial hardware which is located on io
address higher than $3ff. Seems unlikely to me. In your former post, you
tried to access io address 1000 (decimal) this is $3e8 (hexadecimal) and
should be an ordinary COM3. May be you are mixing up decimal vs.
hexadecimal notation.

Regards, Bernd.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Access to RS232 ports with fpc

Holger Bruns
Bernd Mueller schrieb:

> Holger Bruns wrote:
>> Holger Bruns schrieb:
>>> I try to implement a direct port access. If this also leads to
>>> access errors, I should give it up. Embarassing.
>> Accessing ports is limited to ports < 03ffh, more ports cannot be
>> released with fpioperm. This means to me, successful serial port
>> access on higher addresses cannot yet be implemented with fpc. If
>> this policy can be ruled out, let me know.
>
> so you must use a very special serial hardware which is located on io
> address higher than $3ff. Seems unlikely to me. In your former post,
> you tried to access io address 1000 (decimal) this is $3e8
> (hexadecimal) and should be an ordinary COM3. May be you are mixing up
> decimal vs. hexadecimal notation.
>
No, the "1000" means the size of a buffer, not a part address. The port
address I try to use is 0xEC00, which is the base address for an UART on
a PCI card. Linux sees this UART as /dev/ttyS2. Accessing the registers
direcly should be easy, because 3 lines of assembler code should do this
job:

function readport (portaddress: word): byte;
begin
 asm
  mov %dx, portaddress
   inb %al,%dx
  mov readport, %al
 end
end;

As long as the pascal syntax and the assembler syntax (instruction
destination source) are both correct for fpc, this function should
return the value of the selected port. This is all, what I try to do.


Best regards, Holger

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Access to RS232 ports with fpc

Gustavo Enrique Jimenez
> No, the "1000" means the size of a buffer, not a part address. The port
> address I try to use is 0xEC00, which is the base address for an UART on a
> PCI card. Linux sees this UART as /dev/ttyS2. Accessing the registers
> direcly should be easy, because 3 lines of assembler code should do this
> job:
>
> function readport (portaddress: word): byte;
> begin
> asm
>  mov %dx, portaddress
>  inb %al,%dx
>  mov readport, %al
> end
> end;
>
> As long as the pascal syntax and the assembler syntax (instruction
> destination source) are both correct for fpc, this function should return
> the value of the selected port. This is all, what I try to do.
>
>
> Best regards, Holger
>

Just user synaser,  http://www.synapse.ararat.cz/ . When you get the
thing working, go back to the serial unit. I do SCADA with Modbus
through serial port. Never had a problem.
You can't write programs in linux (or windows) like in DOS.

Gustavo
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
12