3.2. IFactory

Class for port connection to printer

3.2.1. GetPort

Opens a port for communicating with the printer.

  • Declaration

    IPort GetPort(string portName, string portSettings, int timeout)
    
  • Parameter

    Name Contents Type
    portName The printer port name string
    portSettings Specifies connection setting information. string
    timeout The timeout time for internal control and API (unit: millisecond) int
  • Return value

    Contents Type
    IPort object IPort
  • Exception

    Contents Type
    When port open fails
    When an incorrect portName is passed
    PortException
  • Error code

    Value Contents
    StarResultCode.ErrorFailed Some kind of error occurred
    StarResultCode.ErrorInUse Connection was refused by the printer (another host is connected or other reason)

Refer to Printing flow .

  1. portName Parameter

Interface

portName

Contents

Example

Library version

Bluetooth BT:Bluetooth COM Port

To specify the Bluetooth com port

"BT:COM3" 2.3.0+
BT:MAC Address

To specify the MAC address

"BT:00:12:F3:1E:2B:72" 2.5.0+
Ethernet/Wireless LAN TCP:IP Address

To specify the IP address

"TCP:192.168.1.100"2.3.0+
USB Printer Class USBPRN:Printer Queue Name

To specify the printer queue name

"USBPRN:Star MCP31/30" 2.3.0+
USB Vendor Class USBVEN:
Communicates with the first Star printer found.
Connect only one Star USB printer with.
"USBVEN:" 2.3.0+
USBVEN:USB Serial Number

Specifying USB serial number

"USBVEN:1234ABCD" 2.3.0+
USBVEN:COM Port

To specify the com port

"USBVEN:COM3" 2.3.0+
Parallel LPT Port Number

To specify the parallel port name

"LPT1" 2.3.0+
Serial Serial Port Number

To specify the serial port Name

"COM1" 2.3.0+
USB/Bluetooth/LAN AutoSwitch:

Using AutoSwitch Interface

"AutoSwitch:"2.7.0+
  • AutoSwitch Interface

    This function automatically detects ports for connecting to a printer. It detects connectable ports according to the following order of priority.

    1. USB
    2. Bluetooth
    3. LAN

    The procedure for this function is as follow.

    1. Prepare an environment so that Windows Device can be connected with the printer via Bluetooth or LAN.

      • Pair Windows Device with the printer via Bluetooth.
      • Connect Windows Device and the printer to the same network (same segment).
    2. Connect Windows Device with the printer via USB.

    3. Specify “AutoSwitch:” for portName, and then execute this method.

    4. If Windows Device is successfully connected with the printer via USB, Step 3 is succeeded. If not, check the USB connection of Windows Device and the printer, and then try Step 3 again.

    5. Specifying “AutoSwitch:” for portName can help Windows Device automatically connect using other interfaces even if it is not connected with the printer via USB.

    If you want to change the printer to use, start over from Step 1.

    We recommend using this function in the following cases.

    • When you can prepare an environment so that multiple interfaces including USB can be used.
    • When the connected interface is frequently changed during operation.
    • When you do not want to know the connected port in the program.

    Important

    • Enable the USB serial number setting for the printer.
    • Do not perform the USB connection and Bleutooth pairing with any other printers except for the connected printer.
    • If using a LAN interface, prepare the environment so that UDP port 22222 can be used.

    Warning

    • This function may require more time until you can start printing than specifying a port directly.

    Following models support this function.

    Model Firmware version
    mC-Print2 1.0+
    mC-Print3 1.0+

    Warning

    • Not support MCP20/MCP30
  1. portSettings Parameter

    The portSettings string is specified using the format shown below.

    (serial port settings, if using serial interface) + the identifier that should be used with that model + option specification strings delimited by ‘;’.

    Note

    Serial port settings

    Each fields are a comma-separated string described with
    baudRate , parity , dataBits , stopBits , flowControl .
    ( For example: 9600,n,8,1,n )

    * Baud rates: This field can be one of: 115200 , 57600 , 38400 , 19200 , 9600 , 4800.
    * Parity: This field can be one of: n , e , o.
    n: For none.
    e: For even.
    o: For odd.
    * Data bit This field can be one of: 7 or 8 .
    * Stop bit: This field can be one of: 1 or 2 .
    * FlowControl: This field can be one of: n , h , c , x .
    n: For no flow control
    h: For hardware flow control (DSR)
    c: For hardware flow control (CTS)
    x: For software flow control (Xon/Xoff)

    The setting can be confirmed by
    Test Print which can be executed by holding down the printer’s feed button while turning the printer on.

    The identifier that should be used with each model is as shown below.

    Model

    Emulation

    Identifier

    mC-Print2 StarPRNT ""
    mC-Print3 StarPRNT ""
    mPOP StarPRNT ""
    FVP10 StarLine ""
    TSP100IIIW StarGraphic ""
    TSP100IIIBI StarGraphic ""
    TSP100IIIU StarGraphic ""
    TSP100ECO StarGraphic ""
    TSP100U StarGraphic ""
    TSP100GT StarGraphic ""
    TSP100LAN StarGraphic ""
    TSP650II StarLine ""
    TSP650IISK StarLine ""
    TSP700II StarLine ""
    TSP800II StarLine ""
    SM-S210i StarPRNT "Portable"
    EscPosMobile"mini"
    SM-S220i StarPRNT "Portable"
    EscPosMobile"mini"
    SM-S230i StarPRNT "Portable"
    EscPosMobile"mini"
    SM-T300i/T300 StarPRNT "Portable"
    EscPosMobile"mini"
    SM-T400i StarPRNT "Portable"
    EscPosMobile"mini"
    BSC10 EscPos "escpos"
    SM-L200 StarPRNT "Portable"
    SM-L300 StarPRNT "Portable"
    SP700 StarDotImpact ""

    The option specification strings are shown below.

    Interface

    Option type

    Contents

    Example

    Library version

    Bluetooth

    d[value]

    Data timeout function timeout value setting.

    If the d option is not specified with a model that supports the data timeout function, the data timeout function is enabled and the timeout value is set to 3 seconds.

    The method for specifying the timeout time is the following.

    1. If a value from 1 to 255 was specified for [value]: Time that was specified for [value]
    2. If 0 was specified for [value] : Data timeout function is ignored
    3. Other than the above: 3 seconds
    "d10"2.3.0+

    l[value](lower case “L”)

    Connection retry will be performed.

    The method for specifying the retry time is the following.

    1. If a value will not be specified (“l” only) : Timeout time specified by the getPort
    2. If a value from 0 to 300000 was specified for [value]: Time that was specified for [value] (units: milliseconds).
    3. If a value of 300001 or more was specified for [value] : Timeout time specified by the getPort
    4. Other than the above: Retry is not performed.
    "l10000"2.3.0+
    Ethernet/Wireless LAN

    l[value](lower case “L”)

    Connection retry will be performed when the target printer is in use by another host.

    The method for specifying the retry time is the following.

    1. If a value will not be specified (“l” only) : Timeout time specified by the getPort
    2. If a value from 0 to 300000 was specified for [value]: Time that was specified for [value] (units: milliseconds).
    3. If a value of 300001 or more was specified for [value] : Timeout time specified by the getPort
    4. Other than the above: Retry is not performed.
    "l10000"2.4.1+
    • Data timeout function

      The data timeout function is a function which ignores the remaining print data when data was not sent to the printer within the specified length of time during printing.
      This function prevents corruption of the next print contents after the Bluetooth connection was disconnected during data sending.
      For usable models, refer to below.
      Model Firmware version
      mC-Print2 1.0+
      mC-Print3 1.0+
      mPOP 1.0+
      FVP10 2.0+
      TSP100IIIBI 1.0+
      TSP650II 2.0+
      TSP650IISK 1.0+
      TSP700II 5.0+
      TSP800II 2.0+
    • Example of portSettings

    Printer connection environment portSettings
    Uses TSP650II as the default setting. “”
    Uses mC-Print3 with retry enabled by Ethernet interface. “;l10000”
    Uses SM-L200 as the default setting “Portable”
    If data is not sent for 10 seconds during printing withTSP650II, it operates the data canceling function. “;d10”

3.2.2. ReleasePort

Closes a port for communicating with the printer.

  • Declaration

    void ReleasePort(IPort port)
    
  • Parameter

    Name Contents Type
    port A IPort object previously created by the GetPort method IPort
  • Return value

    None

Refer to Printing flow .

Important

Notes on compatibility

Beginning from StarIO.dll V2.6.0 (StarPRNT SDK V5.11.0), the readPort method behavior has been changed as shown below.

  • StarIO.dll *V2.5.0 and before

    In the case of calling getPort method multiple times before calling releasePort method, the port is released by calling releasePort method the same number of times as the getPort method was called.

  • StarIO.dll V2.6.0 and later

    The port is always released when releasePort method is called.

3.2.3. SearchPrinter

Search the Star printer and return search results.

  • Declaration

    List<PortInfo> SearchPrinter()
    List<PortInfo> SearchPrinter(PrinterInterfaceType target)
    
  • Parameter

    When the argument is omitted, the printer of all interfaces is searched.

    Name Contents Type
    target Specify the Printer Interface Type [1] [2] PrinterInterfaceType
    [1]

    Serial port interface and parallel port interface search detects whether or not the corresponding port is installed on the PC. It does not detect whether or not a printer is connected to the port.

    [2]

    When searching for a Bluetooth printer, there are cases when it is not possible to search depending on the Bluetooth driver that is installed. When printer search is not possible, refer to Checking the Bluetooth Virtual COM Port and check the information needed for connecting to the printer. Searching for a Bluetooth printer is possible when the Microsoft Bluetooth driver is used.

  • Return value

    Contents Type
    Search result of Star printer
    Refer to PortInfo class.
    List<PortInfo>
  1. Restrictions

    This API do not guarantee the discovery of devices.

3.2.4. GetStarIOVersion

Get the version number of the StarIO library.

  • Declaration

    string GetStarIOVersion();
    
  • Parameter

    None

  • Return value

    Contents Type
    StarIO library version string