본문 바로가기

카테고리 없음

Freebasic Serial Port Programming

Port

Sending Commands in BASIC to ADRInterfacesOPENING A SERIAL FILESending commands to the or any other ADR interface using aterminal or computer running a terminal emulation program is simply a matter of typing incommands and pressing return. With BASIC it can be just as simple. The ADR101 isconnected to the computer via a serial cable and BASIC treats the ADR101 as a serial file.Before commands can be sent to the ADR101 this serial file must be opened and initialized.This should be done at the start of any program that is to access the ADR101.The commandto open a serial file is shown below;10 OPEN 'COM1:9600,n,8,1,CS,DS,RS' AS#1This line opens a serial file and labels it as serial file #1. Thisallows access to the ADR101 using PRINT#1 and INPUT#1 commands.SENDING COMMANDSSending commands in BASIC to the ADR101 can be done using PRINT#1commands. For example, sending an RA0 command could be done as shown below;20 PRINT#1, 'RA0'Extra spaces inside the quotes are ignored by the ADR101.

Avoidsending commands on consecutive lines because a carriage return is not sent after thefirst command resulting in an unrecognized command. This problem arises with theconfiguring of a digital port and then trying to access the port immediatly after it isconfigured.

Windows serial port programming

A REM statement should be inserted between consecutive PRINT#1 commands asshown below; 20 PRINT#1, 'CPA00000000'30 REM FORCES40 PRINT#1, 'SETPA0'Variable names may also be used with PRINT#1 commands. One exampleof this shown below.

Serial Port Programming In C#

This program configures PORT A as output and the increments it from 0to 255. 10 OPEN 'COM1:9600,n,8,1,CS,DS,RS' AS#120 PRINT#1, 'CPA00000000'30 FOR X = 0 to 25540 PRINT#1, 'MA',X50 NEXT X60 ENDRECEIVING DATAWhen reading analog inputs or the digital port, data is sent fromthe ADR101 to the computers serial buffer. This data can be retrieved using INPUT#1commands. The INPUT#1 command should be used following PRINT#1 commands if data isexpected to be sent by the ADR101. If a single piece of data is expected then one variablename should be used with the INPUT#1 command. If eight pieces of data are to be receivedas with the RPA command then eight variable names must be used with the INPUT#1 command.Examples of both cases are shown below; 20 PRINT#1, 'RA0'30 INPUT#1, ANADAT40 PRINT#1, 'RPA'50 INPUT#1, PA7,PA6,PA5,PA4,PA3,PA2,PA1,PA0The variable names used in the INPUT#1 commands now contain the datasent by the ADR101.

Sorry if this seems like a shamless plug. But I have no association with this freeware project other than being a happy user.

Serial Port Programming

But, I think many here could find it very useful. And I couldn't believe the search here didn't find any posts about it.I see a lot of people complaining about using IO in WinXP because of the security layer MS added to access IO ports directly - Good news. You do this in FREEBasic directly with.no. need for an external lib/dll (you use INP and OUT statements just like in QuickBasic). The IO driver built in to the compiler (Freebasic is compiled not interpreted and its pretty fast too) and adds only 4KB or so to the compiled exe.All you need is to run the compiled exe as an administrator the first time (The IO driver stays in memory until you reboot). FreeBASIC - as the name suggests - is a completely free, open-source, 32-bit BASIC compiler, with the syntax the most compatible possible with MS-QuickBASIC, that adds new features such as pointers, unsigned data types, inline-assembly and many others.Theres a wiki for it too.Its definitly a great language for working with I/O on a winXP machine (Linux and DOS versions available, and cross platform is usually considered) and its syntax is much easier to follow than C. And its free too.Many popular libs are already set to use - OpenGL, FMOD, DirectX, WinAPI, Freetype.

Well heres a list of all the libs that have already converted header files and comes with the full freebasic package)you can find various user libs for graphics, networking, sound, etc. So be sure to search there too. Pretty active there, and pretty helpful users.oops.