Inpout32 Dll Serial Port Examples Of Alliteration

Inpout32 Dll Serial Port Example. 7/22/2017 0 Comments VS 2010 Writing To Parallel Port. Inp and Out declarations for port I/O using inpout32.dll. Apr 30, 2014 Highrez. Welcome to the. His previous post about 'opening the serial port'. I'm using inpout32.dll on a Windows 7. Pointers (messy but fine for an example.

Contents • • • • • LPT Ports Parallel Ports do Not Require an External LPT Device Connection to Function. Example 1: Reading the Parallel Port Data, Status and Control register settings before and after reversing it. 'inpout32' Inp32% ( PortAddress ) Out32 ( PortAddress, Value ) baseadd = 888 'base address for most LPT printers is 378 LPTport (baseadd) 2 Out32 baseadd + 2, 32 'set control bit 6(C5) high to reverse port to read incoming data 2 'sets Data port to 0. May not work on all parallel ports LPTport (baseadd) 2 Out32 baseadd + 2, 12 'control port is normally set to 12 Out32 baseadd, 227 'any ASCII code value from 0 to 255. Code 227 prints p character LPTport (baseadd) LPTport (address) basedata% = Inp32(address) 'Data:'; basedata%; (basedata%) 'read or write 'Status:'; Inp32(address + 1) 'base + 1 read only status from device!

'Control:'; Inp32(address + 2) 'base + 2 read or write. 32 or over reverses port Contributed by Ted Weissgerber Data: 255 Status: 120 Control: 12 Data: 0 Status: 120 Control: 32 Data: 227 π Status: 120 Control: 12 Parallel Port Registers Note: The normal LPT1 base port is &H378(888), but it could also be &H278(632) or &H3BC(956). __________________________________________________________ / 13 12 11 10 9 8 7 6 5 4 3 2 1 / S4 S5 S7 S6 D7 D6 D5 D4 D3 D2 D1 D0 C0 / 25 24 23 22 21 20 19 18 17 16 15 14 / G7 G6 G5 G4 G3 G2 G1 G0 C3 C2 S3 C1 / ______________________________________________/ DB-25 Female 10 Ack, 11 Busy, 12 PaperOut, 13 Select, 14 LFeed, 15 Error DO NOT RUN HIGH CURRENT DEVICES with the 5 volt DC output! Use with a separate power supply. Use appropriate grounding between devices with the 8 ground pins(green in Pinout diagram) provided!

Data Register (BaseAddress) Read or Write in normal operation. D0 to D7 data byte values from 0 to 255 can be converted to characters in a device. Setting the byte value can turn certain pins on or off to control switching devices. Read only to read input in reverse mode set by C5 bit on. Software control in normal output mode.

Data pin voltages can be set to 0 or 5 volts DC in Reverse mode only! • Pin values on: D0(+ 1), D1(+ 2), D2(+ 4), D3(+ 8), D4(+ 16), D5(+ 32), D6(+ 64), D7(+ 128) Note: The Data port will be in normal output mode and set to 255 with all pins on at startup or reboot!

Reverse read only mode may set all byte values to 0 or 255 if all pins are held high by the port for pull down input. Status Register (BaseAddress + 1) Read only! Register normally used to monitor the status of a printer or other device that is connected to the parallel port. Pins S3 to S6 are held high by resistors so that it will read 120(or 127) when nothing is connected to the pins.

A device can manipulate the read only status port value by grounding certain pins. When 5 volts is fed to a pin, bit will stay on. S7 is inverted so that it adds 128 to the port value when it is grounded. Otherwise S7 is 0 by default.

S0, the timeout bit, can be reset off by software when set by EPP mode. Bits S1 and S2 are not used. If the port reads 255 the parallel port is not installed. Pin voltages can be set to 0 or 5 volts DC by chip devices or grounding switches to turn bits 3 to 6 off or bit 7 on. • S0 Low can be set in EPP mode timeout only(normally off).

INP32(889) 1 = 1 when bit is on (no pin) • S3 Low for error, offline or paper end(normally on). INP32(889) 8 = 8 when bit is on, pin is high • S4 High for printer selected(normally on). INP32(889) 16 = 16 when bit is on, pin is high • S5 High for out of paper(normally on). INP32(889) 32 = 32 when bit is on, pin is high • S6 Low for Acknowledge(normally on). INP32(889) 64 = 64 when bit is on, pin is high • S7 High for busy, offline, error.(normally off) INP32(889) 128 = 128 when bit is on, pin is pulled low Bit S0 has no pin and can be set at a timeout or reset to 0 by software in EPP mode only. Pin S7 is inverted so that a low pin signal turns the bit on. 4 bit binary data can be read using pins S3 to S6.

The port byte value can be divided by 8 to get the decimal values 0 to 15. Control Register (BaseAddress + 2) Read or Write.

Register is used to send messages to a printer or other device that is connected to the port. Usually the port sets itself to read 12(C2 and C3 on) after about 30 seconds. The C0, C1, and C3 pins are inverted while C2 is not.

Inverted pins are set on when a bit is set low(off). C4 and C5 have no pins, but can be set internally by a program. Setting C4(16) can turn off the IRQ interrupt. When C5 is on(32) the Data port is reversed to read data sent from a device. Software or port hardware controls the port. Do NOT attempt to change pin voltages! • C0 Low(bit on) pulse strobe data sent.(normally off) OUT32 890, INP32(890) 1 turns bit on, pin low • C1 Low(bit on) linefeed or auto feed.(normally off) OUT32 890, INP32(890) 2 turns bit on, pin low • C2 Low(bit off) pulse Initiate.(normally on) OUT32 890, INP32(890) 4 turns bit on, pin high • C3 Low(bit on) printer select in.(normally on) OUT32 890, INP32(890) 8 turns bit on, pin low • C4 High(bit on) IRQ interrupt off(normally off).

OUT32 890, INP32(890) 16 turns bit on (no pin) • C5 High(bit on) reverse data port for input read only(normally off). OUT32 890, INP32(890) 32 turns bit on (no pin) Red pin numbers are inverted so that bits on set corresponding output pins low and bits off set pins high.

Bits C4 and C5 designate internal(no pin) software enabled control port register bits Use OUT32 with to turn a bit on or to change the current bit status. INP32 with can determine if a bit is on or off(0). () COM Ports Serial Communication Ports Require an External Serial Device or PC COM Port Connection to function! Example 2: A 3 wire Teletype program that allows two computers to serially communicate through each keyboard: 'inpout32' Inp32% ( PortAddress ) Out32 ( PortAddress, Value ) Baseadd% = 3F8 'any valid COM port address (see the Windows Hardware COM port Properties) Out32 Baseadd% + 3, 80 'set Divisor Latch Access Bit using 128 Hex (LCR) 'Out32 Baseadd%, 60 ' 1200 baud 96 Write DL Low Byte 'Out32 Baseadd%, 30 ' 2400 48 'Out32 Baseadd%, 18 ' 4800 24 Out32 Baseadd%, C ' 9600 12 Maximum baud rate in QB! Out32 Baseadd% + 1, 0 'Write DL High Byte 'Set Base and IER back to normal registers, and set Data requirements Out32 Baseadd% + 3, 3 'set 8 bit word(bit0 + bit1=3), 1 Stop Bit(0ff), No Parity(0ff) 'COM should now be set as N, 8, 1 by the LCR.

Like an statement. Out32 Baseadd% + 2, 3 'Flush receiver FIFO buffer, enable FIFO (FCR): x$ = x$ = (27) 'Escape key quits x$ >' Out32 Baseadd%, (x$) 'Write Transmit buffer data (Inp32(Baseadd% + 5) 1) 'Data ready = 1 (LSR) (Inp32(Baseadd%)); 'Display Receive buffer data' Adapted from code by T3SL4 Possible port addresses are &H3F8(1016) = COM1, &H2F8(760) = COM2, &H3E8(1000) = COM3 and &H2E8(744) = COM 4. Connect each COM port transmit line to the opposing receive line on the other PC.

Connect both COM grounds together. Serial Communication Ports Require an External Serial Device or PC COM Port Connection to function!

() Serial Communication Registers Two PC's can communicate between the COM ports using a. _______________________________ / 5 4 3 2 1 / GND DTR TXD RXD DCD / 9 8 7 6 / RI CTS RTS DSR / ___________________/ RS-232 Female (DB-9) DCD = Data Carrier Detect, RXD = Receive Data, TXD = Transmit Data, DTR = Data Terminal Ready, GND = Signal Ground DSR = Data Set Ready, RTS = Request to Send, CTS = Clear to Send, RI = Ring Indicator Serial Communication Ports Require an External Serial Device or PC COM Port Connection to function! A Serial port can use extra Registers due to the use of a UART chip.

When the Base Address is Read, the chip supplies the data from the FIFO(First In First Out) Receive Buffer. When Written to, it sends data to the FIFO Transmit Buffer.

If the DLA Bit is On in the LCR register, then the UART base register accepts the Divisor Latch Low Byte data. Address DLAB INP/OUT Abb.

Thank you for trying. But, I don't understand.

The script is running OK and have been tested with my LPT Hardware. I'm using thinBasic 1.8.9.0 on XEON 3.2GHz with 32-bit XP SP3. The inpout32.dll should be placed in the same folder of the application, or in System32 or simply in Windows folder. Correction: You're right, Petr. I've mistakenly zipped the wrong file. It should've been tb_ltp8rel_gui.tbasic! I have added the correct.zip file on the first post.

Btw, here's the code. Please try again and I would love to know how it goes.

Declare Sub Out32 Lib 'inpout32.dll' Alias 'Out32' (ByVal portaddress As Word, ByVal portvalue As Byte) Declare Function Inp32 Lib 'inpout32.dll' Alias 'Inp32' (ByVal portaddress As Word) As Byte Why? Well, because the Inp32 returns a value. When procedure does not return value, it is SUB, when it returns value, it is FUNCTION.

The program runs okay now on my PC! Thanks, Petr. Yesterday, I was curios about what is/are the difference/s between Sub and Function. So, I did a simple experiment. Here is the code.

Sub Relay(ByVal N As Integer, ByVal V As Boolean) LPTValue = 0 '#1 - reset the LPTValue with zero LPTValue = Inp32(LPTAddress) '#2 - read data port using Inp32(), and still a Sub rather than Function Console_Write LPTValue '#3 - printout the data port If V Then LPTValue = LPTValue Or RelayOn(N) Else LPTValue = LPTValue And RelayOff(N) End If Out32(LPTAddress, LPTValue) End Sub The result is the LPTValue printed out by Console_Write is correct. If the Sub Inp32() doesn't return a value, than LPTValue should be zero. So, using Sub Inp32() has no problem because it is in fact returning the correct value. And then I tried this code. Hi, Petr has explained the situation in a perfect way. In thinBasic, SUB and FUNCTIONS are synonymous. The interpreted nature of thinBasic permits to make internal manipulation of data the way we like.

SUB and FUNCTIONS syntax are present for compatibility with other Basic programming languages letting easy copy/paste of code in/out of thinBasic. Zte Mf65m Cdc Serial Driver. The above for native thinBasic SUB and FUNCTIONS. A completely different situation occurs when SUB and FUNCTIONS are used to DECLARE external function libraries (DLLs).

In those case a perfect match between DECLARE and known external SUB or FUNCTIONS must take place because depending on the type of the declare (SUB or FUNCTION) calling process have to get and clear returning data (if needed). Also a perfect match of passed parameters must take place otherwise a stack calling corruption (and quite sure a GPF) is just round the corner. Global LPTAddress As Word = &H378 Global LPTValue As Byte Dim RelayOn(8) As Byte = [1, 2, 4, 8, 16, 32, 64, 128] Dim RelayOff(8) As Byte = [255-1, 255-2, 255-4, 255-8, 255-16, 255-32, 255-64, 255-128] ' -- Create dialog here Function TBMain() Local hDlg As DWord. End Function Idea #1: The DIM keyword You can use the DIM keyword to specify not just arrays, but also variables. In case you use DIM in global space, it becomes global variable, in case you us DIM in local space, it becomes local variable.

The code above would become. Dim LPTAddress As Word = &H378 Dim LPTValue As Byte Dim RelayOn(8) As Byte = 1, 2, 4, 8, 16, 32, 64, 128 ' -- Note: The [] brackets are not necessary for 1D array, they serve to force row order assignment in 2D arrays. In 1D they can be used too, but they make no effect. Dim RelayOff(8) As Byte = 255-1, 255-2, 255-4, 255-8, 255-16, 255-32, 255-64, 255-128 ' -- Create dialog here Function TBMain() Dim hDlg As DWord.

End Function Idea #2: Super short variable declaration Inspired by some other languages, you can use short variable declaration with default types too. The code would become this.