Имя: Пароль:
1C
1С v8
Отправка команды на com port
0 babiy
 
19.06.12
14:58
Здраствуйте. Мне нужно отправить команду на компорт (оборудование)из 1С 8.1. Как это можно реализовать? Напрямую через 1С или ВК?
1 palpetrovich
 
19.06.12
15:04
сам как думаешь?
2 Kreont
 
19.06.12
15:09
3 Jaap Vduul
 
19.06.12
15:11
FileSystemObject = Новый COMОбъект("Scripting.FileSystemObject");
com1 = fso.OpenTextFile("com1:",1,);
4 Jaap Vduul
 
19.06.12
15:16
(3) - это на чтение
На запись:
com1 = fso.OpenTextFile("com1:", 2, Ложь, 0);
5 palpetrovich
 
19.06.12
15:16
(3) что, правда прокатит?
6 Jaap Vduul
 
19.06.12
15:17
(5)Про DOS слышал?
7 palpetrovich
 
19.06.12
15:18
(6) а то
8 palpetrovich
 
19.06.12
15:22
+7 проверил на ХР, действительно, в лоб файл com1 не создать :) ...хотя умельцы умеют
9 babiy
 
19.06.12
15:55
Извините, а можна подробней о параметрах:
OpenTextFile("com1:", 2, Ложь, 0);

у меня в отладке:

com1.AtEndOfLine = Ошибка чтения значения
com1.AtEndOfStream = Ошибка чтения значения
com1.Column = 1
com1.Line = 1

я з 1С недолга работаю и с ком-портом первый раз.
10 mikecool
 
19.06.12
15:59
а тупо бат формировать с "copy file com1" или как там в досе было?
11 babiy
 
19.06.12
16:48
Подробней о OpenTextFile:

"OpenTextFile Method  

Description
Opens a specified file and returns a TextStream object that can be used to read from, write to, or append to the file.
Syntax
object.OpenTextFile(filename[, iomode[, create[, format]]])
The OpenTextFile method has these parts:

Part Description
object Required. Always the name of a FileSystemObject.
filename Required. String expression that identifies the file to open.
iomode Optional. Indicates input/output mode. Can be one of three constants: ForReading, ForWriting, or ForAppending.
create Optional. Boolean value that indicates whether a new file can be created if the specified filename doesn't exist. The value is True if a new file is created; False if it isn't created. The default is False.
format Optional. One of three Tristate values used to indicate the format of the opened file. If omitted, the file is opened as ASCII.  


Settings
The iomode argument can have either of the following settings:
Constant Value Description
ForReading 1 Open a file for reading only. You can't write to this file.
ForWriting 2 Open a file for writing only. You can't read from this file.
ForAppending 8 Open a file and write to the end of the file.


The format argument can have any of the following settings:

Constant Value Description
TristateUseDefault -2 Opens the file using the system default.
TristateTrue -1 Opens the file as Unicode.
TristateFalse  0 Opens the file as ASCII.


Remarks
The following code illustrates the use of the OpenTextFile method to open a file for writing text:
Sub OpenTextFileTest
 Const ForReading = 1, ForWriting = 2, ForAppending = 8
 Dim fso, f
 Set fso = CreateObject("Scripting.FileSystemObject")
 Set f = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)
 f.Write "Hello world!"
 f.Close
End Sub" Microsoft® Visual Basic® Scripting Edition
12 babiy
 
19.06.12
16:50
Но здесь указываеться файл .txt, а как указать ком-порт?
13 Shurjk
 
19.06.12
16:55
(12) С точки зрения системы когда она пишет в файл который называется COM1 она пишет в ком порт.
14 smaharbA
 
19.06.12
16:56
восьмерка может это делать и объектом ТекстовыйДокумент

вот пути правильно таковые \\.\com1
15 Shurjk
 
19.06.12
16:58
(14) Вообще все равно как это делать. Вот только с чтением этот вариант врят ли поможет. Ком порт он ведь не стоит и не ждет пока ты его прочитаешь, он отправил данные и все твоя задача успеть их поймать.
16 Shurjk
 
19.06.12
16:59
+(15) Короче надо по любому писать ВК или найти уже готовое, которое будет уметь слушать ком порт.
17 babiy
 
19.06.12
17:16
Мне читать ненужно, мне толька подавать команды и писать. Всем большое спасибо!!! Буду тестировать. Щас нету просто возможности увидить попадает в компорт или нет.
18 babiy
 
20.06.12
12:43
Здраствуйте. В ком нечего не попадает. Вот код который я использую:

 Команда = ЭлементыФормы.Команда1.Значение;
 fso = Новый COMОбъект("Scripting.FileSystemObject");
 f = fso.OpenTextFile("\\.\com9", 2, Ложь, 0);
 f.Write (Команда);
 
В чем может быть проблема?
Независимо от того, куда вы едете — это в гору и против ветра!