You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -19,24 +21,34 @@ If an existing file is opened for output, the file will be deleted and an empty
19
21
The files are always opened as shared. You can use FREEFILE to get the next unused file-handle. Use PRINT,
20
22
INPUT, BGETC and BPUTC to read from or write to a file or device.
21
23
22
-
### Open RS232, socket, URL or image
24
+
#### Open a COM port (RS232)
25
+
26
+
You can open a connection to a device using the serial port with `open "COMn:speed" AS #1`, where `n` is the number of the port
27
+
and `speed` is the baud rate. To open the first serial port with a baud rate of 19200 use: `open "COM1:19200" as #1`. In Windows
28
+
COM1 and in Linux /dev/ttys1 would be opened.
23
29
24
-
With OPEN you can also open a network connection. Depending on the kind of connection the following file names can be used:
30
+
#### Open a TCP/IP socket
25
31
26
-
| Connection Type | Example |
27
-
|---------------------|---------|
28
-
| URL | `open "http://api.duckduckgo.com/?q=Cars&format=json" as #1`
29
-
| Image |`open "http://img2.wikia.nocookie.net/__cb20150113215904/farmville/images/9/92/Lumberjack_Gnome-icon.png" as #1`|
30
-
| Socket |`open "SOCL:192.168.178.76:8080" as #1`|
31
-
| Serial Port (RS232) |`open "COM1:19200" as #1`|
32
+
You can open a connection to a device using a TCP/IP socket with `open "SOCL:IP:PORT" AS #1`, where `IP` is a valid host name or IP address
33
+
and `port` is an open port.
32
34
33
-
More information with examples can be found in the article "Network programming".
35
+
`open "SOCL:192.168.178.76:8080" as #1`
34
36
35
-
#### Open COM port (RS232)
37
+
If you omit the host name or IP address in the `SOCL:` string passed to the OPEN command, SmallBASIC will listen for connections from another host/process.
36
38
37
-
You can open a connection to a device using the serial port with `open "COMn:speed" AS #1`, where n is the number of the port
38
-
and speed is the baud rate. To open the first serial port with a baud rate of 19200 use: `open "COM1:19200" as #1`. In Windows
39
-
COM1 and in Linux /dev/ttys1 would be opened.
39
+
`open "SOCL:8080" as #1`
40
+
41
+
### Open an image
42
+
43
+
Use the prefix `HTTP:` with the `OPEN` command to open an image file over the network. You can then pass the file number to the `IMAGE` command. This returns an system object which can then be used to manipulate images in the graphical version of SmallBASIC.
44
+
45
+
`open "http://img2.wikia.nocookie.net/__cb20150113215904/farmville/images/9/92/Lumberjack_Gnome-icon.png" as #1`
46
+
47
+
### Open a HTTP connection
48
+
49
+
Use the prefix `HTTP:` with the `OPEN` command to open a network HTTP connection. You can then use the file number with the `TLOAD` command to read the data.
50
+
51
+
`open "http://api.duckduckgo.com/?q=Cars&format=json" as #1`
40
52
41
53
### Example 1: Open a file:
42
54
@@ -61,17 +73,17 @@ wend
61
73
close #1
62
74
```
63
75
64
-
### Example 2: Open a socket
76
+
### Example 2: Open a socket for listening (server)
65
77
66
78
```
67
79
open "SOCL:10000" as #1 ' Open socket at port 10000
68
80
69
-
while (eof(1)) ' Loop until connection is closed
81
+
while (!eof(1)) ' Loop until connection is closed
70
82
71
83
l = lof(1) ' Querry how much data is in the queue
72
84
73
85
if(l) then ' if data is available
74
-
s = INPUT(l, #1) ' get all data
86
+
s = INPUT(l, 1) ' get all data
75
87
print s
76
88
endif
77
89
@@ -80,17 +92,27 @@ wend
80
92
close #1
81
93
```
82
94
83
-
### Example 3: Open a COM port (RS232)
95
+
### Example 3: Open a socket as client
96
+
97
+
```
98
+
open "SOCL:192.168.1.10:10000" as #1 ' Connect to server
99
+
100
+
print #1, "Hello world" ' Send string to server
101
+
102
+
close #1
103
+
```
104
+
105
+
### Example 4: Open a COM port (RS232)
84
106
85
107
```
86
108
open "COM1:19200" as #1 ' Open COM1 with 19200 bauds
87
109
88
-
while (eof(1)) ' Loop until connection is closed
110
+
while (!eof(1)) ' Loop until connection is closed
89
111
90
112
l = lof(1) ' Querry how much data is in the queue
91
113
92
114
if(l) then ' if data is available
93
-
s = INPUT(l, #1) ' get all data
115
+
s = INPUT(l, 1) ' get all data
94
116
print s
95
117
endif
96
118
@@ -99,3 +121,46 @@ wend
99
121
close #1
100
122
```
101
123
124
+
### Example 5: Open an image over network
125
+
126
+
```
127
+
' open some random image I found on the net
128
+
open "http://img2.wikia.nocookie.net/__cb20150113215904/farmville/images/9/92/Lumberjack_Gnome-icon.png" as #1
129
+
130
+
i = image(#1)
131
+
i.show(100,50)
132
+
```
133
+
134
+
### Example 6: Connect to an HTTP server
135
+
136
+
```
137
+
print "DuckDuckGo Search"
138
+
while 1
139
+
print '<=== when cycle around need to isolate input prompt
140
+
input "(Just enter quits) Term? ", queryTerm
141
+
if trim(queryTerm)="" then ? "Cheers!":end '<=== need a way out
0 commit comments