Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add functionality to set DTR/RTS line status on serial port open #813

Merged
merged 2 commits into from Mar 31, 2023

Conversation

@cheton cheton self-assigned this Feb 19, 2023
@cheton cheton linked an issue Feb 19, 2023 that may be closed by this pull request
9 tasks
@cheton cheton requested review from MitchBradley and a team February 19, 2023 12:06
@cheton cheton force-pushed the cncjs-812 branch 2 times, most recently from fe36f54 to 6c4d32b Compare February 19, 2023 12:53
@cheton cheton changed the title feat: add functionality to reset board by toggling Data Terminal Ready (DTR) signal upon serial port open feat: add functionality to reset board by setting Data Terminal Ready (DTR) signal upon serial port open Feb 21, 2023
@cheton cheton changed the title feat: add functionality to reset board by setting Data Terminal Ready (DTR) signal upon serial port open feat: add functionality to reset board by enabling Data Terminal Ready (DTR) pin upon serial port open Feb 21, 2023
@cheton cheton marked this pull request as draft February 21, 2023 10:25
@cheton cheton removed request for a team and MitchBradley February 21, 2023 10:25
@cheton
Copy link
Collaborator Author

cheton commented Mar 30, 2023

Translated by gpt-35-turbo

cs

Nastavit stav řádky DTR při otevírání
Nastavit stav řádky RTS při otevírání
Použijte řízení toku RTS/CTS
[NASTAVIT] [VYMAZAT]

de

Setze den DTR-Leitungsstatus beim Öffnen
Setze den RTS-Leitungsstatus beim Öffnen
Verwende RTS/CTS-Flusskontrolle
[SETZEN] [LÖSCHEN]

en

Set DTR line status upon opening
Set RTS line status upon opening
Use RTS/CTS flow control
[SET] [CLR]

es

Establecer el estado de la línea DTR al abrir
Establecer el estado de la línea RTS al abrir
Utilice control de flujo RTS/CTS
[ESTABLECER] [BORRAR]

fr

Définir l'état de la ligne DTR à l'ouverture
Définir l'état de la ligne RTS à l'ouverture
Utilisez le contrôle de flux RTS/CTS
[ÉTABLIR] [CLR]

hu

DTR vonal állapotának beállítása az nyitáskor
RTS vonal állapotának beállítása az nyitáskor
Használjon RTS/CTS áramvezérlést
[BEÁLLÍT] [TÖRLÉS]

it

Imposta lo stato della linea DTR all'apertura
Imposta lo stato della linea RTS all'apertura
Utilizzare il controllo di flusso RTS/CTS
[IMPOSTA] [CANCELLA]

ja

開くときにDTRラインの状態を設定する
開くときにRTSラインの状態を設定する
RTS/CTSフロー制御を使用する
[設定] [クリア]

nb

Sett DTR-linjestatus ved åpning
Sett RTS-linjestatus ved åpning
Bruk RTS/CTS strømstyring
[SETT] [SLETT]

nl

Stel DTR-lijnstatus in bij opening
Stel RTS-lijnstatus in bij opening
Gebruik RTS/CTS-stroomregeling
[INSTELLEN] [WISSEN]

pt-br

Definir status da linha DTR na abertura
Definir status da linha RTS na abertura
Use o controle de fluxo RTS/CTS
[DEFINIR] [LIMPAR]

pt-pt

Definir estado da linha DTR na abertura
Definir estado da linha RTS na abertura
Use o controlo de fluxo RTS/CTS
[DEFINIR] [LIMPAR]

ru

Установить статус линии DTR при открытии
Установить статус линии RTS при открытии
Используйте контроль потока RTS/CTS
[УСТАНОВИТЬ] [ОЧИСТИТЬ]

tr

Açılışta DTR hat durumunu ayarla
Açılışta RTS hat durumunu ayarla
RTS/CTS akış kontrolü kullanın
[AYARLA] [TEMİZLE]

zh-cn

打开时设置DTR线路状态
打开时设置RTS线路状态
使用RTS/CTS流控制
[设置] [清除]

zh-tw

開啟時設置DTR線路狀態
開啟時設置RTS線路狀態
使用RTS/CTS流量控制
[設置] [清除]

@cheton cheton mentioned this pull request Mar 30, 2023
9 tasks
@cheton cheton changed the title feat: add functionality to reset board by enabling Data Terminal Ready (DTR) pin upon serial port open feat: add functionality to set DTR/RTS line status upon serial port open Mar 30, 2023
@cheton cheton changed the title feat: add functionality to set DTR/RTS line status upon serial port open feat: add functionality to set DTR/RTS line status on serial port open Mar 30, 2023
Copy link
Contributor

@emcniece emcniece left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good from out here. Unit tests complain about some evaluate-expression things but it ends with 483 passing ok :)

Copy link
Contributor

@MitchBradley MitchBradley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code seems solid but I think there is a better approach. Some MCUs, including ESP32, require a pulse on RTS with DTR held in a particular state. To handle this, I propose a string whose characters define a sequence of states:

  • d means DTR low
  • D means DTR high
  • r means RTS low
  • R means RTS high
  • nnn (a decimal number) means delay that many milliseconds
  • optional spaces for readability

An ESP32 reset would thus be "Dr50R". The existing cases could be handled with, for example, "", "d", "D", "r", "R", "dR", etc. There would only need to be one variable that could handle all situations. It could even handle delay-after-open with just a number, like "1000" for wait one second before proceeding.

A little more refinement:

  • empty string means "perform the controller-specific default reset sequence"
  • "0" means "do nothing, overriding the controller's default sequence". It is equivalent to "delay 0 milliseconds", so does not require a special case in the parser

@MitchBradley
Copy link
Contributor

Here is an untested SWAG at a parser for a reset string. I haven't written any Javascript lately so I might be missing something or doing something in a dumb or obsolete way, but this is the basic idea:

let delayval = null;
function doDelay() {
    if (delayval !== null) {
        await delay(delayval);
        delayval = null;
    }
}
function parseResetString(str) {
    delayval = null;
    if (str === "") {
        controller.resetSequence();
        return;
    }
    for (let c of str) {
        switch (c) {
                case ' ':
                break;
            case 'd':
                doDelay();
                await this.connection.port.set({ ...setOptions, dtr: false}); 
                break;
            case 'D':
                doDelay();
                await this.connection.port.set({ ...setOptions, dtr: true}); 
                break;
            case 'r':
                doDelay();
                await this.connection.port.set({ ...setOptions, rts: false}); 
                break;
            case 'R':
                doDelay();
                await this.connection.port.set({ ...setOptions, rts: true}); 
                break;
            case '0':
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
                if (delayval == null) {
                    delayval = delayval * 10 + (c.charCodeAt() - '0');
                }
                break;
            default:
                // Some form of error message goes here
                break;
        }
    }
    doDelay();
}

@cheton
Copy link
Collaborator Author

cheton commented Mar 31, 2023

Looks good from out here. Unit tests complain about some evaluate-expression things but it ends with 483 passing ok :)

The error message that was generated was intentional and can be safely disregarded.

@cheton
Copy link
Collaborator Author

cheton commented Mar 31, 2023

The code seems solid but I think there is a better approach. Some MCUs, including ESP32, require a pulse on RTS with DTR held in a particular state. To handle this, I propose a string whose characters define a sequence of states:

It sounds like a good approach for handling MCU reset with RTS and DTR sequence. I have created an issue to add this to the backlog for further improvement.

@cheton cheton merged commit cb26c1c into master Mar 31, 2023
3 checks passed
@cheton cheton deleted the cncjs-812 branch March 31, 2023 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incompatibility with G2Core
3 participants